본문 바로가기
Back/JAVA

[문제] 알파벳을 Z~A순서로 역순 출력

by 시월해 2021. 3. 3.
	public static void main(String[] args) {
		
		for(char c='Z'; c>='A'; c--) {
			for(char d='A'; d<=c; d++) {
				System.out.print(d);
			}
			System.out.println();
		}
		
		System.out.println();
		
		// ASCII코드를 이용하는 방법
		for(int i=90; i>=65; i--) {
			for(int j=65; j<=i; j++) {
				System.out.print((char)j);
			}
			System.out.println();
		}

	}

결과. for문 중 d<=c 조건식이 가장 중요.