004-001-003
Conditional Branching: Grade Evaluator
Medium
Problem Description
Problem Overview
Create a program that inputs a test score and displays the grade evaluation.
Input Format
Receive 1 line of input:
- Score (integer from 0 to 100)
Output Format
Display grade based on the following criteria:
- 90 and above: A
- 80 to 89: B
- 70 to 79: C
- 60 to 69: D
- Below 60: F
Output format: Score: [score] -> Grade: [grade]
Notes
- Display "Invalid score" for scores below 0 or above 100.
Test Cases
※ Output examples follow programming industry standards
Input:
95
Expected Output:
Score: 95 -> Grade: A
Input:
82
Expected Output:
Score: 82 -> Grade: B
Input:
75
Expected Output:
Score: 75 -> Grade: C
Input:
65
Expected Output:
Score: 65 -> Grade: D
Input:
45
Expected Output:
Score: 45 -> Grade: F
Input:
90
Expected Output:
Score: 90 -> Grade: A
Input:
-5
Expected Output:
Invalid score
Input:
105
Expected Output:
Invalid score
❌ Some tests failed
Your Solution
Current Mode:● My Code
99
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
›
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// ユーザーからスコア値を入力
int score = sc.nextInt();
// 有効: の範囲チェック
if (score < 0 || score > 100) {
System.out.println("Invalid score");
return;
}
// 成績評価
String grade;
// [if文] 条件分岐
if (score >= 90) {
grade = "A";
} else if (score >= 80) {
grade = "B";
} else if (score >= 70) {
grade = "C";
} else if (score >= 60) {
grade = "D";
} else {
grade = "F";
}
// 結果をユーザーにコンソール経由で表示
System.out.println("Score: " + score + " -> Grade: " + grade);
}
}
0 B / 5 MB
You have 10 free executions remaining
