Java #29: How to Use A Switch Statement in Java

—————————Full Source Code————————

//Programmer: Akinwale Owi
//Company: Dagba Computers
//Program Purpose: Switch Statement Example in Java

package dagba.computer.sample;

/**
*
* @author Akin
*/

//imports
import java.util.Scanner;

public class DagbaComputerSample {

/**
* @param args the command line arguments
*/

public static void main(String[] args)
{
//Creating the Scanner we will read the user’s choice with
Scanner clientChoice = new Scanner(System.in);

//Asking the user a question
System.out.println(“Welcome to my menu! Please enter choice below:”);
System.out.println(“Enter 1 for keyboard review”);
System.out.println(“Enter 2 for mouse review”);
System.out.println(“Enter 3 for monitor review”);
System.out.println(“————————“);
//Reading in their response
int client = clientChoice.nextInt();

switch (client)
{
case 1:
System.out.println(“Ours are comfortable”);
break;
case 2:
System.out.println(“Fit your hand perfectly”);
break;
case 3:
System.out.println(“Clear as day”);
}
}//end of main function

}//end of DagbaComputerSample Class

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: