2022.11.04 JAVA 7일차 배열
2022. 11. 21. 21:33ㆍJAVA
배열
같은타입의 여러 변수를 하나의 묶음으로 다루는것을 의미 함.
배열 선언과 생성
타입[] 변수이름;
예)
int[] score;
String name[];
타입 변수이름[];
예)
int[] score;
String name[];
배열에 배열명은 그 배열에 시작주소를 가리킨다. ★★★★★
/*
* 배열
* 5개의 정수를 입력받은 후 차례대로 출력하는 프로그램
* 입력예)
* 5 10 9 3 2
* 출력예)
* 5 10 9 3 2
*/
//배열 미사용
// int a,b,c,d,e;
// a = sc.nextInt();
// b= sc.nextInt();
// c = sc.nextInt();
// d = sc.nextInt();
// e = sc.nextInt();
//
// System.out.println("" + a + b + c + d + e);
//배열을 사용하되 반복문 x
// int[] a = new int[5];
// a[0] = sc.nextInt();
// a[1] = sc.nextInt();
// a[2] = sc.nextInt();
// a[3] = sc.nextInt();
// a[4] = sc.nextInt();
//
// System.out.println("" + a[0] + a[1] + a[2] + a[3] + a[4]);
//배열 + 반복문
int[] a = new int [5];
int i;
for(i = 0; i < a.length; i++)
{
a[i] = sc.nextInt();
}
for(i = 0; i <a.length ; i++)
{
System.out.print(a[i]);
}
'JAVA' 카테고리의 다른 글
| 2022.11.08 JAVA 9일차 선택정렬 알고리즘 (0) | 2022.11.21 |
|---|---|
| 2022.11.07 JAVA 8일차 배열2 (1) | 2022.11.21 |
| 2022.11.03 JAVA 6일차 반복제어문(while, do~while) (0) | 2022.11.21 |
| 2022.11.02 JAVA 5일차 반복문(for) (0) | 2022.11.21 |
| 2022.11.01 JAVA 4일차 조건문(switch) (0) | 2022.11.21 |