我的switch語句只是保持循環。它應該打印您選擇的選項,然後重新打印菜單。請幫忙! 這裏是我的代碼:在Java中切換循環
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;
}
}
爲什麼你需要擺在首位的循環? 「if」語句是否足夠?如果你想重印菜單,循環現在不會那樣做;也許循環應該包含該塊。 –
不,它需要在輸入您的選擇後繼續打印菜單。 0退出 – Josh
這就是我說的循環不會那樣做的意思。您的循環體只會打印該選項,直到它爲0,並且主體中沒有任何設置將其設置爲0.您還需要一個'do ... while'循環以及打印邏輯。 –