Java 如何遍历数组里面的数据?

2025-04-15 13:44:28
推荐回答(1个)
回答1:

二维数组定义:数据类型[][] 数组名 = new 数据类型[二维数组行数][二维数组列数]

如:int[] array = new int[5][4];

二维数组的遍历:需要使用两个变量来分别遍历行和列,具体遍历方法就很多啦,可以使用while语句、do-while语句、for语句,也可以相互结合使用。

如:

int i = 0, j = 0;
for(int i = 0; i < array.length; i++){
for(int j = 0; j < array[i].length; j++){
System.out.println(array[i][j] + "、");
}
System.out.println("");
}