我已经用java写了这个并且不断得到一个没有if错误的else。我一遍又一遍地检查它,找不到错误。如果他们与程序的其余部分有问题,这真的是一个缺失吗?
public class Password {
public static void main(String[] args) {
//int Counter = 0;
String[] UserName = {
"William Whitcomb" , "Pamela Healy" ,
"Dennis Clark" , "Troy Bingham" ,
"Bill Mauler"
};
String[] Password = {
"WWhit0523" , "PHeal0854" ,
"DClar1053" , "TBing1272" ,
"BMaul0968"
};
String EnterName = JOptionPane.showInputDialog ( "Enter a valid user name.", //Name pane window
"User Name");
String EnterPassword = JOptionPane.showInputDialog ( "Enter a valid password.", //Age pane window
"Password");
for (int Counter = 0; Counter < UserName.length;){
Validate();
if (Validate() = true) {
JOptionPane.showMessageDialog (null, "You entered the User Name of " + UserName[Counter] +
"and the password of " + Password[Counter]); //Results pane
}
} //End of for
} //End of Method
Boolean Validate(String EnterName , String EnterPassword){
Boolean Condition = false;
if (EnterName.equals(UserName[Counter])) {
if (EnterPassword.equals(Password[Counter])) {
Condition = true;
return //Condition;
} else {
JOptionPane.showMessageDialog (null, "You have entered an invalid password.");
Counter += 1;
} //End of Inner Else
} else {
JOptionPane.showMessageDialog (null, "You have entered an invalid user name.");
Counter += 1;
} //End of Outer Else
} //End of outer if
} //End of Method
} //End of Class