二维数组遍历最佳方法,代码如下
package 629niuniu.com;
public class Test6 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[][] arr = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
System.out.println("遍历二维数组:");
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
}
遍历的结果是:
遍历二维数组:
1 2 3
4 5 6
7 8 9