Java Switch Case Example


A switch statement will match the value in switch() with all the values in the list, if match it will execute that statement, otherwise, it will execute the default statement.

Program
public class SwitchCase { public static void main(String args[]) { switch('C') { case 'A' : System.out.println("Excellent!"); break; case 'B' : case 'C' : System.out.println("Well done"); break; case 'D' : System.out.println("Failed"); default : System.out.println("Invalid grade"); } } }
Input
Output