How to make Nested switch case in java

The switch case statement also use instead of if-else statement. Website development company use switch case statement result in better performance. It can also use as a part of another statement. This switch is called a nested switch.

 

Switch (days) {

Case 0:

Switch (target) {

Case 1:

System.out.printIn( “ target is 1 to 7. ” ) ;

Break;   }

Break;

Case 1:

System.out.printIn( “ Sunday ” ) ;

Break;

Case 2:

System.out.printIn( “ Monday ” ) ;

Break;

Case 3:

System.out.printIn( “ Tuesday ” ) ;

Break;

Case 4:

System.out.printIn( “ Wednesday ” ) ;

Break;

There are three important features of switch statement:-

 

  • The switch can only test for equality, whereas if can test for any type of Boolean expression.

 

  • No two case constant in the same switch can have identical values.

 

  • A switch statement is more useful than nested –if statement.