Results 1 to 10 of 10
  1. #1
    abimaran is offline Member
    Join Date
    Nov 2009
    Location
    Colombo, Sri Lanka
    Posts
    22
    Rep Power
    0

    Post Java Array Assignments?

    Given:
    Java Code:
    byte[] array1, array2[];
    byte array3[][];
    byte[][] array4;
    If each array has been initialized, which statement will cause a Compiler Error?

    Give me the answer and the reasons. Thanx n advanced!

    1) array2 = array1;
    2) array2 = array3;
    3) array2 = array4;
    4) Both 1 & 2.
    5) Both 1 & 3.
    6) Both 2 & 3.
    Last edited by abimaran; 11-04-2009 at 06:21 PM.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,762
    Blog Entries
    7
    Rep Power
    21

    Default

    Homework?

    kind regards,

    Jos

  3. #3
    abimaran is offline Member
    Join Date
    Nov 2009
    Location
    Colombo, Sri Lanka
    Posts
    22
    Rep Power
    0

    Default

    No, JosAH. I'm preparing for SCJP 6 exam.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,762
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by abimaran View Post
    No, JosAH. I'm preparing for SCJP 6 exam.
    Well, count the number of dimensions for each array and see for yourself.

    kind regards,

    Jos

  5. #5
    abimaran is offline Member
    Join Date
    Nov 2009
    Location
    Colombo, Sri Lanka
    Posts
    22
    Rep Power
    0

    Default

    Can we assign one Dimentional array into 2 - Dimentional array and we've to assign every member of one array to other by using a loop?

    Here??
    Last edited by abimaran; 11-04-2009 at 06:39 PM.

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by abimaran View Post
    ...

    Give me the answer and the reasons. Thanx n advanced!

    ...
    What is your answer and what are your reasons?

  7. #7
    abimaran is offline Member
    Join Date
    Nov 2009
    Location
    Colombo, Sri Lanka
    Posts
    22
    Rep Power
    0

    Default

    The answer should be within those 6 answers.

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,762
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by abimaran View Post
    The answer should be within those 6 answers.
    Of course; otherwise you would've gotten lots of replies telling you that the correct answer wasn't in the list. btw, have you been a victim of the ferocious brain eater? Is it still hungry? What do you think the answer is?

    kind regards,

    Jos

  9. #9
    abimaran is offline Member
    Join Date
    Nov 2009
    Location
    Colombo, Sri Lanka
    Posts
    22
    Rep Power
    0

    Default

    array1 is 1D array and array2, array3, array4 are 2D arrays. In JAVA, declaring an array means it(JAVA) creates a variable with a reference to an array. All arrays are technically 1D arrays, Multi dimensional arrays are arrays of arrays.

    So, Can we assign 1D array variable into 2D array variable?

  10. #10
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,762
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by abimaran View Post
    array1 is 1D array and array2, array3, array4 are 2D arrays. In JAVA, declaring an array means it(JAVA) creates a variable with a reference to an array. All arrays are technically 1D arrays, Multi dimensional arrays are arrays of arrays.

    So, Can we assign 1D array variable into 2D array variable?
    Suppose the first line isn't yelled at by the compiler, what is the second line supposed to do?

    Java Code:
    int[][] array2d= new int[42]; // assign a 1d array to a 2d ref.
    array[1][1]= 54; // where should this be stored?
    kind regards,

    Jos

Similar Threads

  1. How to transfer 1D array in JAVA to 3D array in C
    By fishwater00 in forum New To Java
    Replies: 0
    Last Post: 07-31-2009, 07:24 PM
  2. New to java, need a little help with array input
    By black06vfr in forum New To Java
    Replies: 11
    Last Post: 04-29-2009, 06:46 PM
  3. how to convert a Java array to a java stack?
    By pompeez in forum New To Java
    Replies: 2
    Last Post: 08-13-2007, 03:41 PM
  4. Help with string and array in java
    By zoe in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:12 AM
  5. Help with array in java
    By coco in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 05:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •