Page 1 of 1
About Question enthuware.ocajp.i.v7.2.1380 :
Posted: Wed Feb 17, 2016 1:02 pm
by NickWoodward
int[][][] arr3 = {arr2};
so the brackets surrounding arr2 represent the third dimension of the array, and arr2 is a 2d element inside that dimension?
that is an evil question
Nick
Re: About Question enthuware.ocajp.i.v7.2.1380 :
Posted: Wed Feb 17, 2016 8:39 pm
by admin
That is correct.
Re: About Question enthuware.ocajp.i.v7.2.1380 :
Posted: Thu Sep 21, 2017 8:46 am
by Kevin30
To simplify the principle, the following is a valid 2-dimensional array:
int[][] array2D = {{1,2}};
But what does it look like?
In trying out the code, I've figured out that:
array2D[0][0] = 1
array2D[0][1] = 2
But what about array2D[1]?
Is it null? It doesn't look like it. When I try to print it, I get a ArrayIndexoutofBoundsExeption.
Re: About Question enthuware.ocajp.i.v7.2.1380 :
Posted: Thu Sep 21, 2017 8:55 am
by admin
You get a ArrayIndexoutofBoundsExeption upon accessing array2D[1] because the length of array2D is 1. It has only one element, which is accessed through array2D[0].
array2D[0] points to an array of 2 elements i.e. { 1, 2 }. That is why when you do array2D[0][0], you get 1, and when you do array2D[0][1], you get 2.
HTH,
Paul.
Re: About Question enthuware.ocajp.i.v7.2.1380 :
Posted: Sat Jan 26, 2019 8:08 am
by flex567
The second answer, the correct answer is like this: int [] [] [] array3D = { { {0, 1}, {2, 3}, {4, 5} } };
Is this visual representation correct?

Re: About Question enthuware.ocajp.i.v7.2.1380 :
Posted: Sat Jan 26, 2019 2:15 pm
by admin
Yes, your visual representation is correct.