2015-05-25 53 views
0

我試着運行這個循環在Eclipse:條件在Java中的while循環中不起作用?

String password1= "Victor"; 
String password2 = "Kevin"; 
String password; 
password = JOptionPane.showInputDialog(null, "Please enter the password."); 
while (!password.equals(password1) || !password.equals(password2)) { 
    password = JOptionPane.showInputDialog(null, "Incorrect Password."); 
} 

基本上,我想如果密碼不維克多凱文 while循環重新執行,當它是,它會結束。儘管如此,即使我輸入Victor或Kevin時,我仍然收到「密碼不正確」提示。爲什麼?

回答

2

聲明:

while (!password.equals(password1) || !password.equals(password2)) 

始終是真實的;

嘗試更改「&」符號的管道。

while (!password.equals(password1) && !password.equals(password2))