所以,我正在制作一个简单的猜谜游戏,当用户按下取消按钮时,程序不会退出循环。这是循环
while(playAgain = true){
int n = JOptionPane.showConfirmDialog(null, fields, "Number guessing game", JOptionPane.CANCEL_OPTION);
if(n == JOptionPane.CANCEL_OPTION){
playAgain = false;
}
int randomNumber = randomNumber();
String guess = input.getText();
compare(randomNumber, Integer.parseInt(guess));
}
答案 0 :(得分:10)
应该是
while(playAgain == true){
或
while(playAgain){
不要将[=
] true分配给playagain
使用比较[==
]。
你所做的是将true指定给playagain,然后检查是否为true。所以它总是如此