遍历二维数组
代码,生成一个11×11的二维数组,进行遍历按照11*11进行输出。
public static void main(String[] args) {
int array1[][] = new int[11][11];
array1[1][1]=1;
array1[2][2]=2;
for (int[] item:array1) {
for (int x:item) {
System.out.printf("%d\t",x);
}
System.out.println();
}
}
得到结果
0 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0 0
0 0 2 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0