-4
我想知道我如何跳过我再试一次如果我的输入'输入'是无效的。例如,我输入'o'作为我的选择。它应该显示“无效的输入”,它应该显示菜单部分(再次跳过这个尝试)。请帮帮我。我需要跳过我的代码中的一部分,我不知道如何
public class Menu {
public static void MainMenu() {
Part1 call1 = new Part1();
Part2 call2 = new Part2();
Part3 call3 = new Part3();
Part4 call4 = new Part4();
Scanner in = new Scanner(System.in);
String yn = null;
do {
System.out.println("\t\t---HOMEWORK---");
System.out.println("\tI for PART 1");
System.out.println("\tII for PART 2");
System.out.println("\tIII for PART 3");
System.out.println("\tIV for PART 4");
System.out.print("\tEnter input: ");
String input = in.next();
do {
switch (input) {
case "I":
call1.one();
break;
case "II":
call2.two();
break;
case "III":
call3.three();
break;
case "IV":
call4.four();
break;
case "V":
System.exit(0);
break;
default:
System.out.println("invalid input");
break;
}
System.out.print("try again? -Y- || -N- : ");
yn = in.next();
} while (yn.equalsIgnoreCase("y"));
} while (yn.equalsIgnoreCase("n"));
}
}
像'if(inputWasValid){...}'? – SomeJavaGuy
我想我想说的是,如果我输入了一个无效的输入,它不会让用户选择再试一次。它会显示--HOMEWORK--部分,用户将输入另一个选择 –
@ Ms.Smoak下面的问题值得接受吗? –