My switch statement just keeps looping. It should print the option you choose and then reprint the menu. Please help!
Here is my code:
menu ="\n\t1 Create Account" +
"\n\t2 Check balance" +
"\n\t3 Withdraw" +
"\n\t1 Deposit" +
"\n\t2 Get account ID" +
"\n\t3 Set ID" +
"\n\t1 Display Account Info" +
"\n\t0 Quit\n\n\n";
System.out.println(menu);
System.out.println("\tEnter your selection: ");
option = scan.nextInt();
while (option != 0) {
switch (option) {
case 1: // Enter and Validate SSN
System.out.print("option 1");
break;
case 2: //Enter and Validate Passwords
System.out.print("option 2");
break;
case 3: //Enter,Verify, and Translate a Phone keypad Number
System.out.print("option 3");
break;
case 4: // Enter and Validate SSN
System.out.print("option 4");
break;
case 5: //Enter and Validate Passwords
System.out.print("option 5");
break;
case 6: //Enter,Verify, and Translate a Phone keypad Number
System.out.print("option 6");
break;
case 7: //Enter,Verify, and Translate a Phone keypad Number
System.out.print("option 7");
break;
default: outputString = "\nInvalid Selection\n";
System.out.println(outputString);
break;
}
}
I’m pretty sure it’s your
whileloop that is doing the looping. And you are never changing the value ofoptionwithin the body of the loop, so of course it runs continuously.Presumably, you want to move the line:
To the first line of the loop: