gpt4 book ai didi

java - 简单的登录程序,不知道如何返回主菜单。

转载 作者:行者123 更新时间:2023-12-01 09:55:18 27 4
gpt4 key购买 nike

我正在寻找一种在创建用户后能够返回菜单的方法。任何帮助,将不胜感激。我对编程非常陌生,所以如果您需要更多信息,请告诉我。

    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;
}
}
}
}
}

最佳答案

如果您需要重复某些代码块,请将其放入循环内。

关于java - 简单的登录程序,不知道如何返回主菜单。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37282653/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com