728x90
문제
시험 점수를 입력받아 90 ~ 100점은 A, 80 ~ 89점은 B, 70 ~ 79점은 C, 60 ~ 69점은 D, 나머지 점수는 F를 출력하는 프로그램을 작성하시오.
첫째 줄에 시험 점수가 주어진다. 시험 점수는 0보다 크거나 같고, 100보다 작거나 같은 정수이다.
- 입력 예시 -
// (case 1)
100
- 출력 예시 -
// (case 1)
A
정답 코드
< 내 정답 코드 >
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int score = scan.nextInt();
System.out.println(solution(score));
}
public static char solution(int score) {
if (90 <= score) {
return 'A';
} else if (80 <= score && score <= 89) {
return 'B';
} else if (70 <= score && score <= 79) {
return 'C';
} else if (60 <= score && score <= 69) {
return 'D';
} else {
return 'F';
}
}
}
이것을 주의하자!
- 어렵지 않은 코드다.
'코딩 테스트' 카테고리의 다른 글
[백준] (11720번) 숫자의 합 (0) | 2022.11.19 |
---|---|
[백준] (11654번) 아스키 코드 (0) | 2022.11.19 |
[백준] (8958번) OX퀴즈 (0) | 2022.11.19 |
[백준] (2920번) 음계 (0) | 2022.11.19 |
[백준] (2884번) 알람 시계 (0) | 2022.11.19 |