public class Main {
public static void main(String[] args) {
String slist[] = {"Seoul", "Daejeon", "Pusan", "Kwangju"};
System.out.print("원래의 배열: ");
int i;
for (i = 0; i < slist.length; i++){
System.out.print(slist[i] + " ");
}
System.out.println();
System.out.print("역순된 배열: ");
for (i = slist.length-1 ; 0 <= i ; i--) {
System.out.print(slist[i] + " ");
}
}
}
(출력 예시)
원래의 배열: Seoul Daejeon Pusan Kwangju
역순된 배열: Kwangju Pusan Daejeon Seoul
'컴퓨터관련 > 프로그래밍' 카테고리의 다른 글
| [자바] 배열의 메소드 (0) | 2019.03.27 |
|---|---|
| [자바 ] 난수로 구성된 배열의 합계 구하기 (0) | 2019.03.27 |
| [자바] java.lang.ArrayIndexOutOfBoundsException 오류 (0) | 2019.03.26 |
| [자바] 구구단 출력하기 (for문) (0) | 2019.03.23 |
| [자바] 입력받은 수의 약수를 구하기 (0) | 2019.03.22 |