1switch (variable or an integer expression)
2{
3 case constant:
4 //C Statements
5 ;
6 case constant:
7 //C Statements
8 ;
9 default:
10 //C Statements
11 ;
12}
1public class Test {
2
3 public static void main(String args[]) {
4 // char grade = args[0].charAt(0);
5 char grade = 'C';
6
7 switch(grade) {
8 case 'A' :
9 System.out.println("Excellent!");
10 break;
11 case 'B' :
12 case 'C' :
13 System.out.println("Well done");
14 break;
15 case 'D' :
16 System.out.println("You passed");
17 case 'F' :
18 System.out.println("Better try again");
19 break;
20 default :
21 System.out.println("Invalid grade");
22 }
23 System.out.println("Your grade is " + grade);
24 }
25}