Java - Place default statement in the middle of switch cases

Introduction

The default label may not be the last label to appear in a switch statement and is optional. For example,

Demo

public class Main {
  public static void main(String[] args) {
    int i = 50;/*from  ww w. j  av a 2  s.  c om*/
    switch (i) {
    case 10:
      System.out.println("Ten");
    default:
      System.out.println("No-match"); // Execution starts here
    case 20:
      System.out.println("Twenty");

    }
  }
}

Result

Related Topic