forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwitch.java
More file actions
37 lines (33 loc) · 779 Bytes
/
Switch.java
File metadata and controls
37 lines (33 loc) · 779 Bytes
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
31
32
33
34
35
36
37
package com.examplehub.basics;
import java.util.Scanner;
public class Switch {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Please input your score (0-100):");
int score = scanner.nextInt();
if (score < 0 || score > 100) {
System.out.println("Invalid score");
} else {
char level;
switch (score / 10) {
case 10:
case 9:
level = 'A';
break;
case 8:
level = 'B';
break;
case 7:
level = 'C';
break;
case 6:
level = 'D';
break;
default:
level = 'E';
break;
}
System.out.println(score + " is level " + level);
}
}
}