find grade using switch case condition in java

Solutions on MaxInterview for find grade using switch case condition in java by the best coders in the world

showing results for - "find grade using switch case condition in java"
Clara
13 Feb 2017
1public class Student {
2
3   public static void main(String[] args) {
4      // score (0-100)
5      int score = 79;
6      String grade = null;
7      
8      switch(score/10) {
9        // for >= 90
10        case 10:
11        case 9:
12           grade = "A";
13           break;
14        // for >= 80 and <90
15        case 8:
16           grade = "B";
17           break;
18        // for >= 70 and <80
19        case 7:
20           grade = "C";
21           break;
22        // for >= 60 and <70
23        case 6:
24           grade = "D";
25           break;
26        // for >= 50 and <60
27        case 5:
28           grade = "E";
29           break;
30        // for < 50
31        default:
32           grade = "F";
33           break;
34      }
35      
36      // display result
37      System.out.println("Grade = " + grade);
38   }
39
40}