package algorithm; //三维数组 public class ForEach { public static void main(String[] args) { int a[][][] = new int[][][]{ // 创建并初始化数组 { { 1, 2, 3 }, { 4, 5, 6 } }, { { 7, 8, 9 }, { 10, 11, 12 } }, { { 13, 14, 15 }, { 16, 17, 18 } } }; for (int[][] a1 : a) { // 遍历数组 for (int[] a2 : a1) { for (int a3 : a2) { System.out.print(a3 + " "); } System.out.println(); // 输出一维数组后换行 } } } }