1、二维数组其实就是一个特殊的一维数组,一维数组中每个元素就是一个一维数组
2、三维数组又是一个特殊的二维数组
int[][] a=new int[10][10];
String[][] b=new String[10][10];
//静态初始化
int[][] a={{1,2,3,4},{4,5,6,7},{8,9,10,11}};
//动态初始化
String[][] b=new String[10][10];
b[0]=new String[]{"zahngsan","lisi","wangwu"};
b[1]=new String[]{"java","python","c++"};
public class Text0 {
public static void main(String[] args) {
//静态初始化
int[][] a={{1,2,3,4},{4,5,6,7},{8,9,10,11}};
//遍历
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}
运行结果:
public class Text0 {
public static void main(String[] args) {
//静态初始化
int[][] a={{1,2,3,4},{4,5,6,7},{8,9,10,11}};
//调用print方法
print(a);
}
public static void print(int[][] a){
//遍历
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}