Execute the same statements for several different case labels : Switch Statement « Statement Control « Java Tutorial






public class MainClass {
  
  public static void main(String[] args) {
    char yesNo = 'N';

    switch(yesNo) {
      case 'n': case 'N':
           System.out.println("No selected");
           break;
      case 'y': case 'Y':
           System.out.println("Yes selected");
           break;
    }
  }
}
No 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