Free Flowing Switch Statement Example : Switch « Language Basics « Java






Free Flowing Switch Statement Example

 

public class Main {

  public static void main(String[] args) {
    int i = 0;
    switch (i) {

    case 0:
      System.out.println("i is 0");
    case 1:
      System.out.println("i is 1");
    case 2:
      System.out.println("i is 2");
    default:
      System.out.println("Free flowing switch example!");
    }
  }
}
/*
i is 0
i is 1
i is 2
Free flowing switch example!
*/

   
  








Related examples in the same category

1.Switch DemoSwitch Demo
2.SwitchDemo 2SwitchDemo 2
3.Demonstrates the switch statement.Demonstrates the switch statement.
4.Switch demo with empty case statementSwitch demo with empty case statement
5.Nested Switch Statements Example
6.Switch Demo 2: switch statement with different type of variable