遍歷二維陣列
阿新 • • 發佈:2020-12-25
技術標籤:Java筆記
遍歷二維陣列
程式碼,生成一個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