Java - Console program with a set of menu options
Java - Console program with a set of menu options
CODE
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String userInput = "";
while (!userInput.equalsIgnoreCase("x"))
{
System.out.println("\n1. Option1");
System.out.println("2. Option2");
System.out.println("3. Option3");
System.out.println("4. Option4");
System.out.println("x. Exit");
System.out.print("Enter your choice: ");
userInput = sc.nextLine();
if (!userInput.equalsIgnoreCase("x"))
{
switch (userInput)
{
case "1":
System.out.println("You have selected option 1");
break;
case "2":
System.out.println("You have selected option 2");
break;
case "3":
System.out.println("You have selected option 3");
break;
case "4":
System.out.println("You have selected option 4");
break;
default:
System.out.println("Invalid Option");
break;
}
}
}
sc.close();
}
}
Comments
Post a Comment