Reputation: 301
I was going through one App which is suggested for the OCJP exam. I found one question about the two-dimensional array.
Question: Valid declarations of a two-dimensional array.
Options:
int[][] array2D;
int[2][2] array2D;
int array2D[];
int[] array2D[];
int[][] array2D[];
My selection: int[][] array2D;
and int[] array2D[]
but when I submit my answer it tells me that int[] array2D[]
is wrong and correct is int[][] array2D[];
I think the int[][] array2D[];
is incorrect answer.
int[] array2D[]
recommended in programming?Upvotes: 1
Views: 2650
Reputation: 1161
The answer to this seems to be both options 1 and 4.
int[][] array2D
is a standard way to declare a 2-d int array.
Although int[] array2D[];
it is not a good practice it will work and will be a valid declaration.
Upvotes: 5