본문 바로가기
Algorithm/Beakjoon

[Java] baekjoon 9498 : 시험 성적 / if문

by Amy97 2021. 7. 17.
728x90

문제 


https://www.acmicpc.net/problem/9498

 

9498번: 시험 성적

시험 점수를 입력받아 90 ~ 100점은 A, 80 ~ 89점은 B, 70 ~ 79점은 C, 60 ~ 69점은 D, 나머지 점수는 F를 출력하는 프로그램을 작성하시오.

www.acmicpc.net

해결 


자바 if - else if - else문

1
2
3
4
5
6
7
if (조건식1) {
    실행문1; // 조건식1이 true일 경우 실행
else if (조건식2){
    실행문2; // 조건식2가 true일 경우 실행
else {
    실행문3; // 조건식1 및 조건식2가 false일 경우 실행
}
cs

구현 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
 
        int score = sc.nextInt();
 
        if (90 <= score && score <= 100) {
            System.out.println("A");
        } else if (80 <= score && score <= 89) {
            System.out.println("B");
        } else if (70 <= score && score <= 79) {
            System.out.println("C");
        } else if (60 <= score && score <= 69) {
            System.out.println("D");
        } else {
            System.out.println("F");
        }
 
    }
}
cs

결과 


728x90

댓글