我正在尋找能夠在創建用戶後返回到菜單的方法。任何幫助,將不勝感激。我對編程非常陌生,所以如果你需要額外的信息,請告訴我。簡單登錄程序,不確定如何返回主菜單。
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