gpt4 book ai didi

java - System.out.println() 被跳过

转载 作者:搜寻专家 更新时间:2023-11-01 01:54:36 25 4
gpt4 key购买 nike

在第二个 for 循环没有出现后,我的提示“请输入您的 ID”直接转到“请输入您的密码”。它还跳过了很多从登录提示到密码提示的代码。如果您对它为何如此表现有任何想法,请与我分享,谢谢。

public void main(String[] args){

Accounts Accounts = new Accounts();

Scanner kb = new Scanner(System.in);

System.out.print("Please create a login ID and hit \"ENTER\": ");
Login = kb.nextLine();

for(;;){
if(!Accounts.isTaken(Login)){
System.out.print("Please create a password and hit \"ENTER\": ");
PW = kb.nextLine();
if(Accounts.validPW(PW)){
Accounts.createAccount(Login, PW);
break;
}
}
}

System.out.print("Do you wish to Log in ? (Y/N): ");
String response = kb.nextLine();
if((response=="y")||(response=="Y")){
for(;;){
//Not Being Shown
System.out.println("Please enter your ID: "); // ?????? Where are you?????
Login = kb.nextLine();
Accounts.login(Login);
//Goes straight here
System.out.print("Please enter your Password: ");
if ((Accounts.isValid(Login))&&(Accounts.checkAuth(kb.nextLine()))){
break;
}
else{
System.out.println("Invalid Login-Password!");
}
}
}
System.out.println("Please enter your Password: ");
System.out.println("LOGIN AUTHORIZED: "+Accounts.checkAuth(kb.nextLine()));
}

最佳答案

代替

(response=="y")||(response=="Y")

使用

(response.equals("y"))||(response.equals("Y"))

关于java - System.out.println() 被跳过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13636027/

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