package com.chongrui.test;
/*
*三維數組的初始化及遍歷
* */
public class test {
public static void main(String[] args) {
int a[][][]=new int[][][]{
{{1,2,3},{4,5,6}},
{{8,9,10},{11,12,13}},
{{14,15,16},{17,18,19,20}},
};
for(int i=0;i<a.length;i++){
System.out.println("三維數組的第"+(i+1)+"個元素是一個"+a[0].length+"維數組,內容如下:");
for(int j=0;j<a[i].length;j++){//遍歷數組當中的每個元素,
for(int k=0;k<a[0][0].length;k++){
System.out.print(a[i][j][k]+"\t");//將數組當中每個元素輸出
}
System.out.println(" ");
}
}
}
}
三維數組的第1個元素是一個2維數組,內容如下:
1 2 3
4 5 6
三維數組的第2個元素是一個2維數組,內容如下:
8 9 10
11 12 13
三維數組的第3個元素是一個2維數組,內容如下:
14 15 16
17 18 19