Demonstration of the switch case statement - Java Language Basics

Java examples for Language Basics:switch

Description

Demonstration of the switch case statement

Demo Code

public class Main {
  public static void main(String arg[]) {
    int dd = 3; // 0 for Monday , 6 for Sunday

    switch (dd) {
    case 0:/*  w  w w  .j  a  v a2s . co m*/
      System.out.println("Monday");
      break;
    case 1:
      System.out.println("Tuesday");
      break;
    case 2:
      System.out.println("Wednesday");
      break;
    case 3:
      System.out.println("Thursday");
      break;
    case 4:
      System.out.println("Friday");
      break;
    case 5:
      System.out.println("Saturday");
      break;
    case 6:
      System.out.println("Sunday");
      break;
    default:
      System.out.println("Out of scope!");

    }
  }
}

Result


Related Tutorials