Mega Code Archive

 
Categories / Java Tutorial / Statement Control
 

The switch Statement

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