Nested switch Statements

For example, the following fragment is a valid nested switch statement.

public class Main {
  public static void main(String args[]) {
    for (int i = 0; i < 6; i++)
      switch(i) { 
        case 0: 
          switch(i+1) { // nested switch 
            case 0: 
              System.out.println("target is zero"); 
              break; 
            case 1: 
              System.out.println("target is one"); 
              break; 
          } 
          break; 
        case 2: // ...
     }
  }
}

The output:


target is one
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.