forEach遍历数组 1public class ArrayDemo{2 public static void main(String args []){3 int data [] = new int []{1,2,3,4,5};4 5 for (int temp : data ){6 System.out.println(temp);7 }8 }9} 循环打印二维数组 1public class ArrayDemo{2 public static void main(String args []){3 int data [][] = new int [][] {4 {1,2,3,4,5},{1,2,3},{6,7,8,9}5 };6 for(int x = 0; x < data.length; x++) {7 for(int y = 0; y <data[x].length; y++){8 System.out.println("data["+x+"]["+y+"] = "+data[x][y]);9 }10 System.out.println();11 }12 }13} 用forEach打印二维数组 1public class ArrayDemo{2 public static void main(String args []){3 int data [][] = new int [][] {4 {1,2,3,4,5},{1,2,3},{6,7,8,9}5 };6 for(int temp[]: data ){7 for (int num : temp){8 System.out.print(num+",");9 }10 System.out.println();11 }12 }13}