Nested Switch Statements Example : Switch Statement « Statement Control « Java Tutorial






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








4.3.Switch Statement
4.3.1.The switch Statement
4.3.2.The switch Statement: a demo
4.3.3.Execute the same statements for several different case labels
4.3.4.Free Flowing Switch Statement Example
4.3.5.Nested Switch Statements Example
4.3.6.Switch statement with enum