
학생의 점수를 출력하는 간단한 프로그램을 작성해보자.
package array;
public class Array1 {
public static void main(String[] args) {
int student1 = 90;
int student2 = 80;
int student3 = 70;
int student4 = 60;
int student5 = 50;
System.out.println("학생1 점수 = " + student1);
System.out.println("학생2 점수 = " + student2);
System.out.println("학생3 점수 = " + student3);
System.out.println("학생4 점수 = " + student4);
System.out.println("학생5 점수 = " + student5);
}
}

int형 변수를 계속해서 추가해야 한다. 학생 수가 5명이면 int형 변수 5개를 선언해야 하고, 학생 수가 100명이라면 int형 변수를 100개 선언해야 한다. 결국 비슷한 변수를 반복해서 선언하는 문제가 발생한다.이렇게 같은 타입의 변수를 반복해서 선언하고 반복해서 사용하는 문제를 해결하는 것이 배열이다.