Notice
Recent Posts
Recent Comments
«   2024/09   »
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
Archives
Today
Total
관리 메뉴

충분히 쌓여가는

백준[Java] 9498번 시험 성적 본문

IT/Java[백준]

백준[Java] 9498번 시험 성적

빌드이너프 2023. 2. 14. 14:19

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

 

9498번: 시험 성적

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

www.acmicpc.net


문제풀이

import java.util.Scanner;
public class _9498_1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int score = sc.nextInt();

        if (score >= 90) System.out.println('A');
        else if (score >= 80) System.out.println('B');
        else if (score >= 70) System.out.println('C');
        else if (score >= 60) System.out.println('D');
        else System.out.println('F');
    }
}
  • if 조건문의 기초 문제
  • 삼항연산자를 사용할 수 있지만 개인적으로 가독성이 떨어진다고 생각하기 때문에 기본적인 if 조건문을 사용해 문제 해결

문제풀이 2

import java.util.Scanner;

public class _9498_2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int score = sc.nextInt();

        String result = (score >= 90) ? "A" : (score >= 80) ? "B": (score >= 70) ? "C" : (score >= 60) ? "D" : "F";

        System.out.println(result);
    }
}

문제풀이 3

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class _9498_3 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int score = Integer.parseInt(br.readLine());

        if (score >= 90) System.out.println('A');
        else if (score >= 80) System.out.println('B');
        else if (score >= 70) System.out.println('C');
        else if (score >= 60) System.out.println('D');
        else System.out.println('F');
    }
}

문제풀이 4

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class _9498_4 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int score = Integer.parseInt(br.readLine());

        String result = (score >= 90) ? "A" : (score >= 80) ? "B": (score >= 70) ? "C" : (score >= 60) ? "D" : "F";

        System.out.println(result);
    }
}

 

'IT > Java[백준]' 카테고리의 다른 글

백준[Java] 14681번 사분면 고르기  (0) 2023.02.14
백준[Java] 2753번 윤년  (0) 2023.02.14
백준[Java] 1330번 두 수 비교하기  (0) 2023.02.14
백준[Java] 2588번 곱셈  (0) 2023.02.14
백준[Java] 10430번 나머지  (0) 2023.02.13