-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScoreToLetterGrade.java
42 lines (36 loc) · 1.04 KB
/
ScoreToLetterGrade.java
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
38
39
40
41
42
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ScoreToLetterGrade {
private static int score;
public static void main(String[] args) {
System.out.print("Enetr the score = ");
try {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
score = Integer.parseInt(br.readLine());
char grade = letterGrade(score);
System.out.println("The grade of " + score + " is " + grade);
} catch (NumberFormatException ex) {
System.out.println("Not an integer !");
} catch (IOException e) {
e.printStackTrace();
}
}
public static char letterGrade(int score) {
char grade;
if (score <0 || score > 100)
grade = 'X';
else if (score>=90 && score <=100)
grade = 'A';
else if (score>=80 && score <90)
grade = 'B';
else if (score>=70 && score <80)
grade = 'C';
else if (score>=60 && score <70)
grade = 'D';
else
grade ='F';
return grade;
}
}