我想寫一些代碼,使用戶輸入一個有效的用戶名,他們得到三個嘗試去做。每次我編譯它時,我都會得到一個else if if錯誤,無論我有其他if語句。我一直得到「其他沒有,如果」錯誤
Scanner in = new Scanner(System.in);
String validName = "thomsondw";
System.out.print("Please enter a valid username: ");
String input1 = in.next();
if (input1.equals(validName))
{
System.out.println("Ok you made it through username check");
}
else
{
String input2 = in.next();
}
else if (input2.equals(validName))
{
System.out.println("Ok you made it through username check");
}
else
{
String input3 = in.next();
}
else if (input3.equals(validName))
{
System.out.println("Ok you made it through username check");
}
else
{
return;
}
'如果(條件){}其他{}否則{}'看起來不正確。首先'else'處理情況是錯誤的情況,但是第二個'else'應該處理的情況是什麼? – Pshemo