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
About Question enthuware.ocajp.i.v7.2.1380 :
Moderator: admin
-
- Posts: 29
- Joined: Mon Mar 30, 2015 6:00 pm
- Contact:
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1380 :
That is correct.
If you like our products and services, please help us by posting your review here.
-
- Posts: 28
- Joined: Sun Oct 25, 2015 10:14 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1380 :
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.
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.
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1380 :
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.
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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 202
- Joined: Mon Apr 02, 2018 8:40 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1380 :
The second answer, the correct answer is like this: int [] [] [] array3D = { { {0, 1}, {2, 3}, {4, 5} } };
Is this visual representation correct?
Is this visual representation correct?
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1380 :
Yes, your visual representation is correct.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 91 guests