You have specified 7 items in a 2D array. That could be a [2]x[4] with a zero or a [1]x[7] with seven zeros. Or many others if zeros are assumed.
Jeff Bosch
Ranch Hand
Joined: Jul 30, 2003
Posts: 804
posted
0
Java does not require that subarrays must have the same number of elements. You could easily have a two-d array [5][], which is an array of five arrays. Each contained array could have a different number of elements...
Give a man a fish, he'll eat for one day. <br />Teach a man to fish, he'll drink all your beer.<br /> <br />Cheers,<br /> <br />Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
MI Mohammed
Ranch Hand
Joined: Feb 16, 2005
Posts: 146
posted
0
Hi, the following are way to declare 2D array in java.
1. int [][] array = new int [2][]; 2. int [] array[] = new int [4][]; 3. int []array [] = {{2,4,5,6},{2,3,4,5}};
Whao ! hope it helps. All the best of luck!!!
SCJA(Beta) SCJP 1.4 SCWCD 1.4 SCBCD 1.3 SCBCD 5.0 beta <br />The more practice we get, the better we are at the exams and in life in general. Pls join me at My DEN.
Tony Morris
Ranch Hand
Joined: Sep 24, 2003
Posts: 1608
posted
0
Java does not require that subarrays must have the same number of elements.
From The Java Tutorial (by Sun), under the topic Creating Arrays:
You can also use the newInstance method to create multidimensional arrays. In this case, the parameters of the method are the component type and an array of int types representing the dimensions of the new array.
The next sample program shows how to use newInstance to create multidimensional arrays:
From the topic Retrieving Component Types:
The component type of a multidimensional array is an array. In the next line of code, the component type of the array named matrix is int[]: int[][] matrix = new int[100][100];
[ February 16, 2005: Message edited by: Jeff Bosch ]