004-002-006
Else If: Grade Classification
Easy
Problem Description
Else If: Grade Classification
Learning Objective: Perform multi-level conditional branching with else if
Evaluate test score in 5 levels. Display A-E grade based on score.
Input
Line 1: Score (integer)
Output
Score: [score] pts
Grade: [A/B/C/D/E]
```java
Criteria: 80+ A, 60+ B, 40+ C, 20+ D, <20 E.
Test Cases
※ Output examples follow programming industry standards
Input:
85
Expected Output:
Score: 85 pts Grade: A
Input:
55
Expected Output:
Score: 55 pts Grade: C
Input:
60
Expected Output:
Score: 60 pts Grade: B
❌ 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
›
⌄
⌄
⌄
⌄
⌄
⌄
⌄
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
// ユーザー入力を読むためのキーボードからの入力を読むScannerオブジェクトを作成
Scanner sc = new Scanner(System.in);
// ユーザーからの入力値を読んで格納
int score = sc.nextInt();
// コンソール経由でユーザーに出力を表示
System.out.println("Score: " + score + " pts");
String grade;
// 条件をチェック
if (score >= 80) {
grade = "A";
} else if (score >= 60) {
grade = "B";
} else if (score >= 40) {
grade = "C";
} else if (score >= 20) {
grade = "D";
} else {
grade = "E";
}
// コンソール経由でユーザーに出力を表示
System.out.println("Grade: " + grade);
}
}
0 B / 5 MB
You have 10 free executions remaining
