| Author |
Master Exam Array question
|
AustinRay Lee
Greenhorn
Joined: Dec 30, 2003
Posts: 3
|
|
Can someone explain the answer to this problem, master exam says that answer C below "is wrong because C tries to assign a two-dimensional array where a one-dimensional array is expected." I can see that b is a two-dimensional array, but it looks like b2 is four-dimensional array. So I would expect the answer to say "C is wrong because C tries to assign a two-dimensional array where a four-dimensional array is expected." Or why is b2 considered a one-dimensional array when it has 4 []'s. public class Test{ public static void main(String [] args){ short [][] b = new short [4] [4]; short [][]big = new short [2][2]; short b3 = 8; short b2 [][][][] = new short [2][3][2][2]; // insert code here } } A b2[1][1] = big; B b[1][0] = b3; C b2[0][1][1] = b:
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
Let's start simple and build up ... Whew. Looks like what you can put into any slot is enough dimensions to fill out the original declaration. In "a[1]" that means no more dimensions, only an int. In d[1][1][1] as in your question, only one more dimension.
|
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
|
 |
 |
|
|
subject: Master Exam Array question
|
|
|