Write a program to print remark according to the grade obtained using switch statement


This Java program takes user input of a grade (A, B, C, D or F), converts it to uppercase using Character.toUpperCase() method and uses a switch statement to print a corresponding remark based on the input. Here's how the program works:

  • The program prompts the user to select a grade.
  • The user inputs a grade, which is stored in the variable g.
  • The program converts the input to uppercase using Character.toUpperCase(g) method and assigns it to the variable grade.
  • The program uses a switch statement to check the value of grade and prints the corresponding remark.

Source Code

import java.util.Scanner;
public class Remark_According
{
    public static void main(String args[])
    {
		Scanner input = new Scanner(System.in);
		char g;
		System.out.println("A, B, C, D or F");
		System.out.print("Please Select Grade :");
		g = input.next().charAt(0);
        System.out.println("Grade : " + g);
		char grade = Character.toUpperCase(g);
        switch(grade)
        {
            case 'A':
                System.out.println("Remark : Excellent!");
                break;
            case 'B':
                System.out.println("Remark : Well Done");
                break;
            case 'C':
                System.out.println("Remark : Very Good");
                break;
            case 'D':
                System.out.println("Remark : Good");
                break;
            case 'F':
                System.out.println("Remark : Fail");
                break;
            default:
                System.out.println("Invalid Grade");
				break;
        }
    }
}
 

Output

A, B, C, D or F
Please Select Grade :C
Grade : C
Remark : Very Good