반응형
Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

디케이

java(자바)codeup(코드업)[1254 : 알파벳 출력하기] 본문

CodeUp

java(자바)codeup(코드업)[1254 : 알파벳 출력하기]

디케이형 2020. 12. 28. 00:12
반응형

시작 알파벳과 마지막 알파벳을 입력받아 그 두 알파벳 사이의 모든 알파벳을 출력하시오.

예)

a f   ====> a b c d e f

입력

시작 알파벳과 마지막 알파벳을 공백으로 띄워 입력받는다.(소문자만 입력되고, 사전순으로 입력된다.)

출력

두 알파벳 사이의 모든 알파벳을 출력한다.

입력 예시   예시 복사

d g

출력 예시

d e f g

 

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);	
		char a = sc.next().charAt(0);
		char b = sc.next().charAt(0);
		
		int c = (int) a;
		int d = (int) b;
		if (c < d) {
			while (c <= d) {			
				System.out.print((char)c + " ");
				c++;
			}	
		}
		else if (d < c) {
			while (d <= c) {			
				System.out.print((char)b + " ");
				d++;
			}	
		}else {
			System.out.println(a);
		}
	}
}

 

반응형