二维数组
1.声明二维数组的一般形式
类型 数组名[][];
或类型[][] 数组名;
或类型[]数组名[];
2.二维数组的初始化是在声明数组的同时就为数组元素指定初值。
例如:int int Array [ ] [ ]={ {1,2} {3,4,5} };
3.在Java语言中,由于把二维数组看做是数组的数组,数组空间不一定连续分配,所以要求二维数组每一维的大小相同。
例:
package Chap6_Array;
import java.util.Scanner;
public class Array2_1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[][] a = new int[3][5];
Scanner sc = new Scanner(System.in);
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
a[i][j] = sc.nextInt();
}
}
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
System.out.println(a[i][j]);
}
}
}
}