在第二个 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()));
}