How to Use Switch Statement with a Default Keyword in Java


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

Source Code

package com.beginner.examples;

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

Output:

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