本帖最后由 Oh.Ba 于 2015-5-10 23:29 编辑
最近很多人讨论数组的问题呢,我把我打的三维数组遍历代码分享给大家...
//三维数组遍历
public class SanWeiArray {
public static void main(String[] args) {
int[][][] arr = {
{ { 1, 3, 2, 5 }, { 1, 2, 6, 4, 3 }, { 1, 5, 8, 2, 7 } },
{ { 1, 4, 2, 6 }, { 1, 56, 4, 7 }, { 1, 2, 5, 2, 7, 3 } },
{ { 1, 4, 6, 2, 6 }, { 1, 4, 5, 2 } },
{ { 12, 4 }, { 12, 35, 3 }, { 12, 4 }, { 12, 56, 4, 23, 5 } } };
for (int a = 0; a < arr.length; a++) {
System.out.print("[");
for (int b = 0; b < arr[a].length; b++) {
System.out.print("[");
for (int c = 0; c < arr[a].length; c++) {
System.out.print(arr[a][c]);
if (c < arr[a].length - 1) {
System.out.print(",");
}
}
System.out.print("]");
}
System.out.println("]");
System.out.println();
}
}
}
|
|