The switch Statement: a demo : Switch Statement « Statement Control « Java Tutorial






public class MainClass {
  public static void main(String[] args) {
    int choice = 2;

    switch (choice) {
    case 1:
      System.out.println("Choice 1 selected");
      break;
    case 2:
      System.out.println("Choice 2 selected");
      break;
    case 3:
      System.out.println("Choice 3 selected");
      break;
    default:
      System.out.println("Default");
      break;
    }
  }
}
Choice 2 selected








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