{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Switch - i int choice= a i switch(choice case 1:a=1...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.Scanner; public class Switch { // a class to prompt the user // to enter a integer 1,2,3 or 4 // and print the associated meaning // 1="up", 2="down", 3="left", 4="right" // Use a switch statement / public static void main(String []args) { p Scanner input=new Scanner(System.in); S System.out.println("Enter a number"); int a = input.nextInt();
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: i int choice=+a; i switch (choice) { case 1:a=1; System.out.println("Up"); break; case 2:a=2; System.out.println("down"); break; case 3:a=3; System.out.println("left"); break; case 4:a=4; System.out.println("right"); break; default:System.out.println("unknown action"); d } }//end main } }//end Switch }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online