3-13 SwitchDemo
Post date: Jan 30, 2014 8:44:17 PM
/*
This program demonstrates the switch statement.
*/
package switchdemo;
import java.util.Scanner; // Needed for Scanner class
public class SwitchDemo
{
public static void main(String[] args)
{
int number; // A number entered by the user
// Create a Scanner object for keyboard input.
Scanner keyboard =new Scanner(System.in);
// Get one of the numbers I, 2, or 3 from the user.
System.out.print("Enter 1, 2, or 3: ");
number = keyboard.nextInt();
// Determine the number entered.
switch (number)
{
case 1:System.out.println("You entered l.");
break;
case 2:System.out.println("You entered 2.");
break;
case 3:System.out.println("You entered 3.");
break;
default:System.out.println("That's not 1 , 2, or 3!");
}
}
}