Java二维数组遍历输出的方法有两种常用的方式:
int[][] array = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; for (int i = 0; i < array.length; i++) { for (int j = 0; j < array[i].length; j++) { System.out.print(array[i][j] + " "); } System.out.println(); } 输出结果为:
1 2 3 4 5 6 7 8 9 int[][] array = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; for (int[] row : array) { for (int num : row) { System.out.print(num + " "); } System.out.println(); } 输出结果为:
1 2 3 4 5 6 7 8 9