Nested Switch Statements Example : Switch « Language Basics « Java






Nested Switch Statements Example

 

public class Main {

  public static void main(String[] args) {
    int i = 0;
    switch (i) {
    case 0:
      int j = 1;
      switch (j) {
      case 0:
        System.out.println("i is 0, j is 0");
        break;
      case 1:
        System.out.println("i is 0, j is 1");
        break;
      default:
        System.out.println("nested default case!!");
      }
      break;
    default:
      System.out.println("No matching case found!!");
    }
  }
}
//i is 0, j is 1

    

   
  








Related examples in the same category

1.Switch DemoSwitch Demo
2.SwitchDemo 2SwitchDemo 2
3.Demonstrates the switch statement.Demonstrates the switch statement.
4.Switch demo with empty case statementSwitch demo with empty case statement
5.Free Flowing Switch Statement Example
6.Switch Demo 2: switch statement with different type of variable