Java中的二维数组表示为相同类型的一维数组的数组。通常,它用于表示具有行和列的值表-
public class Creating2DArray { public static void main(String args[]) { int[][] myArray = new int[3][3]; myArray[0][0] = 21; myArray[0][1] = 22; myArray[0][2] = 23; myArray[1][0] = 24; myArray[1][1] = 25; myArray[1][2] = 26; myArray[2][0] = 27; myArray[2][1] = 28; myArray[2][2] = 29; for(int i=0; i<myArray.length; i++ ) { for(int j=0;j<myArray.length; j++) { System.out.println(myArray[i][j]); } } } }
输出结果
21 22 23 24 25 26 27 28 29