我正在寻找能够在创建用户后返回到菜单的方法。任何帮助,将不胜感激。我对编程非常陌生,所以如果你需要额外的信息,请告诉我。简单登录程序,不确定如何返回主菜单。
public static void main(String[] args) {
System.out.println("MAIN MENU");
System.out.println(" ");
System.out.println("1) Creating a Login");
System.out.println("2) Login");
System.out.println("9) Quit");
System.out.println(" ");
System.out.println("Please enter your choice: ");
System.out.println(" ");
Scanner sc = new Scanner(System.in);
int menuOption = sc.nextInt();
while (menuOption != 9) {
if (menuOption == 1) {
System.out.println("Creating Username, please enter a string:");
String user = sc.nextLine();
user = sc.nextLine();
System.out.println("Creating Password, please enter a string:");
String pass = sc.nextLine();
System.out.println("user is" + user);
System.out.println("pass is" + pass);
if (menuOption == 2) {
System.out.println("Please enter your Username");
String inpUser = sc.nextLine();
System.out.println("Now please enter your Password");
String inpPass = sc.nextLine();
if (inpUser.equals(user) && inpPass.equals(pass)) {
System.out.print("Credentials Accepted");
} else {
System.out.print("Credentials Declined Please try again.");
}
}
if (menuOption == 9) {
break;
}
}
}
}
}
这样,只有菜单选项1工作中。 –
我在编辑帖子时可能错过了编辑器中的支架。我也建议将你的代码移到一个开关中。我会编辑我的答案。 – Underbalanced
@DanGreen我已经更新了我的答案,带有一个开关及其更清晰一点 – Underbalanced