1、二维数组可以看成是以数组为元素的数组。例如:
int a[][] = {{1,2},{3,4,5,6},{7,8,9}};
2、java中多维数组的声明和初始化应按从高维到低维的顺序进行,例如:
int a[][] = new int[3][];
a[0] = new int[2];
a[1] = new int[4];
a[2] = new int[3];
int t1[][] = new int[][4];//这种声明是非法的
二维数组初始化:
1、静态初始化:
int intA[][] = {{1,2},{2,3},{3,4,5}};
int intB[3][2] = {{1,2},{,2,3},{4,5}};//非法声明方式
2、动态初始化:
int a[][] = new int[3][5];
int b[][] = new int[3][];
b[0] = new int[2];
b[1] = new int[3];
b[2] = new int[5]; |
|