Font Awesome Icons


Switch statement:

Java switch statement compares the value and executes one of the case blocks based on the condition. It is same as if…else if ladder. Below are some points to remember while working with switch statements:
case value must be of the same type as expression used in switch statement.
case value must be a constant or literal.
case values should be unique. If it is duplicate, then program will give compile time error.
The break statement is used inside the switch to terminate a statement sequence.
The break statement is optional. If omitted, execution will continue on into the next case.

class switch1{

 public static void main(String args[]){

   int i=2;


     case 0:

     System.out.println(“i is 0”);



     case 1:

     System.out.println(“i is 1”);



     case 2:

     System.out.println(“i is 2”);



     case 3:

     System.out.println(“i is 3”);



     case 4:

     System.out.println(“i is 4”);




     System.out.println(“i is not in the list”);