How do I write a program on java that allows a user to choose from a menu of options if the user does not select one of the choices on the menu have the program reprint the menu and ask the user to enter their selection again the program should continue to repeat the menu until the user has selected a valid option once a valid option has been selected the program should print the users selection
1
Expert's answer
2011-06-06T07:42:56-0400
import java.util.*;
public class Menu { & public static void main(String[] args) { Scanner scan = new Scanner(System.in); while (true) { System.out.println("1) action 1"); System.out.println("2) action 2"); System.out.println("3) action 3"); System.out.println("4) action 4"); System.out.println("5) exit"); switch (scan.nextInt()) { case 1: { & System.out.println("action 1 selected"); & break; } case 2: { & System.out.println("action 2 selected"); & break; } case 3: { & System.out.println("action 3 selected"); & break; } case 4: { & System.out.println("action 4 selected"); & break; } case 5: { & return; } default: { & System.out.println("bad selection. try again"); & break;
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment