二维数组的两种遍历方式
[Java] 纯文本查看 复制代码 package com.heima.test;
public class Test01 {
/**
* @param args
*/
public static void main(String[] args) {
int arr [] [] = {{1,2,3},{4,5,6},{7,8,9}};
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length; j++) {
System.out.print(arr[i] [j] + "\t");
}
System.out.println();
}
System.out.println("-------------------------华丽的分割线--------------------------");
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length; j++) {
System.out.print(arr[j] [i] + "\t");
}
System.out.println();
}
}
}
|