Multiple choices: switch case - Java Language Basics

Java examples for Language Basics:switch

Description

Multiple choices: switch case

Demo Code

import java.util.Scanner;

public class Main {
  public static void main(String arg[]) {
    System.out.print("Input a digit in [0..9]:");
    Scanner keyboard = new Scanner(System.in);
    int n = keyboard.nextInt();
    switch (n) {//from  w  ww  . java2  s  .  c o m
    case 0:
      System.out.println("zero");
      break;
    case 1:
      System.out.println("one");
      break;
    case 2:
      System.out.println("two");
      break;
    case 3:
      System.out.println("three");
      break;
    default:
      System.out.println("Above three!");
      break;
    }
  }
}

Result


Related Tutorials