遍历二维数组
简单遍历二维数组:
//关键在于j < array[i].length
//将{1,2}看成数组array={{1,2},{3,4},{5,6},{7,8}}中又存放的数组
//array.length最大为3,array[i].length最大为 1
public class ArrayDemo05 {
public static void main(String[] args) {
int[][] array = {{1,2},{3,4},{5,6},{7,8}};
for (int i = 0; i <array.length ; i++) {
for (int j = 0; j < array[i].length; j++) {
System.out.println(array[i][j]);
}
}
}
}