Nested Switch Statements - Java Language Basics

Java examples for Language Basics:switch

Description

Nested Switch Statements

Demo Code




public class Main {
  public static void main(String[] args) {
    int i = 0;//from  ww  w.  j  a  v a 2 s  . c  o  m
    int j = 1;

    switch (i) {
    case 0:
      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!!");
    }
  }
}
 

Result


Related Tutorials