How to Use Switch Statement in Java


In this example we will show you how to use the switch statement in Java.

Source Code

package com.beginner.examples;

public class Switch {
  public static void main(String[] args) {
    int i = 1;
    // use the switch statement
    switch (i) {
      case 0:
        System.out.println("0");
        break;
      case 1:
        System.out.println("1");
        break;
      case 2:
        System.out.println("2");
        break;
    }
  }
}

Output:

1
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments