배열의 각 요소가 배열
여러 배열을 묶어놓은 것
자료형[][] 배열명;
배열명 = new 자료형[묶음크기][변수 개수];
배열을 묶어서 관리하기 위함
int ar1[]=new int[5];
int ar2[]=new int[5];
//5개의 변수를 가진 2개의 배열을 하나의 배열로 묶음
int ar3[][]=new int[2][5];
배열은 변수를 관리하기 위한 목적으로 만든 구조이며
2차원 배열도 각 변수에 접근하는 방법이 있어야하고, 그 방법이 인덱스이다.
자료형 배열명[][]={
{값1, 값2, ...},
{값3, 값4, ...},
{값5, 값6, ...},
...
};
int array3[][]={
{1, 2, 3, 4, 5},
{6, 7, 8, , 10}
};
1~4번 학생의 국/영/수 점수 정리
import java.util.*;
public class Day02Ex {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int scores[][]=new int[4][3];
String subject[]= {"국어","영어","수학"};
for(int j=0;j<4;j++) {
System.out.println(j+1 +"번 학생점수----");
for(int i=0;i<3;i++) {
System.out.print(subject[i]+ ":");
scores[j][i]=sc.nextInt();
}
}
// 2차원 배열에 저장된 값을 출력
for(int i=0;i<3;i++) {
System.out.print("\t" + subject[i]);
}
System.out.println();
for (int j=0;j<4;j++) {
System.out.print(j+1 + "번:\t");
for(int i=0;i<3;i++) {
System.out.print(scores[j][i]+"\t");
}
System.out.println();
}
}
}