Java switch statement with multiple cases.

Following is the required program.


Live Demo

public class Test {
   public static void main(String args[]) {
      // char grade = args[0].charAt(0); char grade = 'C'; switch(grade) {
         case 'A' : System.out.println("Excellent!"); break;
         case 'B' :
         case 'C' : System.out.println("Well done");
         case 'D' : System.out.println("You passed");
         case 'F' : System.out.println("Better try again");
         default : System.out.println("Invalid grade");
      System.out.println("Your grade is " + grade);


Compile and run the above program using various command line arguments. This will produce the following result −

Well done
Your grade is C