问题:由于某种原因,循环 while (!input.equalsIgnoreCase(passWord))不起作用。即使密码不正确,执行也会直接进入另一个循环。如果有人可以帮助我,我将不胜感激。提前致谢。
public static void main(String[] args) {
final int MAX_PLAYERS = 15 ;
final int MIN_PLAYERS = 9 ;
int players ;
int teamSize ;
int teams ;
int leftOver ;
String input ;
String passWord = "PROSPERO" ;
input = JOptionPane.showInputDialog(" What is the password please ?");
passWord = String.valueOf(input);
while (!input.equalsIgnoreCase(passWord))
{
input = JOptionPane.showInputDialog(" What is the password please ?");
passWord = String.valueOf(input);
}
input = JOptionPane.showInputDialog("Enter the number of players per team :");
teamSize = Integer.parseInt(input) ;
while (teamSize < MIN_PLAYERS || teamSize > MAX_PLAYERS)
{
input = JOptionPane.showInputDialog("Sorry the minimum player" +
" should be at least" + MIN_PLAYERS + " a maximum of " + MAX_PLAYERS) ;
teamSize = Integer.parseInt(input) ;
}
input = JOptionPane.showInputDialog(" Enter the number of players :") ;
players = Integer.parseInt(input) ;
while ( players < 0 )
{
input = JOptionPane.showInputDialog(" Sorry the numbers of players should be greater than 0 . "
+ " Enter again a number : " ) ;
players = Integer.parseInt(input) ;
}
teams = players / teamSize ;
leftOver = players % teamSize ;
JOptionPane.showMessageDialog(null, " There will be " + teams +
"teams" + leftOver + " players leftover" + passWord);
}
郎朗坤
慕标琳琳
相关分类