Turn from: http://blog.csdn.net/java1992/article/details/5808709, I thanked you here.
/*
* Java Learning:
* Use of two-dimensional arrays :
*/
public class Test {
public static void Main (string[] args) {
How to declare a two-dimensional array:
data type [] Array name = new data type [length] [length];
data type [] Array name = {{123},{456}};
/*
int [] arr = {{123},{456}}; Defines two-dimensional arrays of three columns and assigns values
for (int x = 0; x<arr.length; x + +) {//Anchor Line
for (int y = 0; y<arr[x].length; y++) {//position the number of elements per row
System.out.print (Arr[x][y]);
}
System.out.println ("\ n");
}
*/
int [] [] num = new int [3][3]; Defines a two-dimensional array of three rows and three columns
Num[0][0] = 1; Assign a value to the first element of the first row
NUM[0][1] = 2; Assign a value to the second element of the first row
NUM[0][2] = 3; Assign a value to the third element of the first row
NUM[1][0] = 4; Assign a value to the first element in the second row
NUM[1][1] = 5; Assign a value to the second element of the second row
NUM[1][2] = 6; Assign a value to the third element of the second row
Num[2][0] = 7; Assign a value to the first element in the third row
NUM[2][1] = 8; Assign a value to the second element of the third row
NUM[2][2] = 9; Assign a value to the third element of the third row
for (int x = 0; x<num.length; x + +) {//Anchor Line
for (int y = 0; y<num[x].length; y++) {//position the number of elements per row
System.out.print (Num[x][y]);
}
System.out.println ("\ n");
}
}
}
Array value Arr[x][y] indicates that the value specified is the y column of row x.
When using a two-dimensional array object, note the length represented by
The array name is followed by a length (such as Arr.length), which refers to a few rows (row);
Specifies the index with length (such as Arr[0].length), which is the number of elements owned by the row, that is, the column.
Java two-dimensional array learning (GO)