Check Grade Using Switch
This program prints grade description based on grade character using switch.
Problem Statement
Write a Java program that prints grade description for a given grade character.
Source Code
| 1 | public class GradeSwitch { |
| 2 | public static void main(String[] args) { |
| 3 | char grade = 'B'; |
| 4 | switch(grade) { |
| 5 | case 'A': System.out.println("Excellent - Eduinq"); break; |
| 6 | case 'B': System.out.println("Good - Eduinq"); break; |
| 7 | case 'C': System.out.println("Average - Eduinq"); break; |
| 8 | case 'D': System.out.println("Poor - Eduinq"); break; |
| 9 | case 'F': System.out.println("Fail - Eduinq"); break; |
| 10 | default: System.out.println("Invalid grade - Eduinq"); |
| 11 | } |
| 12 | } |
| 13 | } |
Program Output
Good - Eduinq
Explanation
A character variable grade is declared, and switch(grade) matches it against each case to print the corresponding description. Shows how switch can be used with characters to categorize grades.