Language_Coder 534 : 선택제어문 - 자가진단7

boom.jun.cho·2022년 3월 14일
0

Language_Coder_JUNGOL

목록 보기
47/197

문제

영문 대문자를 입력받아
'A'이면 “Excellent”,
'B'이면 “Good”,
'C'이면 “Usually”,
'D'이면 “Effort”,
'F'이면 “Failure”,
그 외 문자이면 “error” 라고 출력하는 프로그램을 작성하시오.

출력

Good

코드

package com.jungol.algorithm047;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner scanner = new Scanner(System.in);
    	
    	char score = scanner.next().charAt(0);
    	
    	// switch문으로도 작성 가능 
    	if(score == 'A') {
    		System.out.print("Excellent");
    	} else if(score == 'B') {
    		System.out.print("Good");
    	} else if(score == 'C') {
    		System.out.print("Usually");
    	} else if(score == 'D') {
    		System.out.print("Effort");
    	} else if(score == 'F') {
    		System.out.print("Failure");
    	} else {
    		System.out.print("error");
    	}
    	
    	scanner.close();
    }
}
profile
하루하루 최선을

0개의 댓글