- 배열을 사용할 수 있는 반복문
- 인덱스 번호가 필요한 경우 for문을 사용
String[] fruits = {"사과","복숭아","딸기"};
int[] n = {1,2,3};
boolean[] b = {true,false,true};
double[] d = {1.1, 2.2, 3.3, 4.4};
for(String x : fruits) {
System.out.print(x + " "); // " " 하는 이유는 배열간의 간격 띄우기위해
}
System.out.println(); // 다음 줄로 넘어가기
for(int x : n) {
System.out.print(x + " ");
}
System.out.println();
for(boolean x : b) {
System.out.print(x + " ");
}
System.out.println();
for(double x : d) {
System.out.print(x + " ");
}
결과값