3-13 SwitchDemo

posted Jan 30, 2014, 12:44 PM by Dlovan ismail   [ updated Jan 30, 2014, 12:45 PM by Karwan Jacksi ]
/*
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!");
            }
    }   
}

ċ
SwitchDemo.java
(1k)
Karwan Jacksi,
Jan 30, 2014, 12:44 PM
Comments