37. Java Program to Grade using Switch Case.
How does this program work?
- In this program you are going to learn about how to check grade using Switch Case.
- This Problem is solved by using Switch Case then we can easily get the Output.
Here is the code
import java.util.Scanner;
public class grade{
public static void main(String[] args) {
System.out.print("Enter grade from (A, B, C or F) : \n");
Scanner obj = new Scanner(System.in);
String str = obj.next();
char grade = str.charAt(0);
switch (grade) {
case 'A':
System.out.println("Grade A - marks >=80\n");
break;
case 'B':
System.out.println("Grade B - marks >=60\n");
break;
case 'C':
System.out.println("Grade C - marks >=40\n");
break;
case 'F':
System.out.println("Grade F - marks <=40 FAIL\n");
break;
default : //optional
System.out.println("Invalid Grade");
break; //optional
}
}
}