public void play() {
int anInteger;
//guess return code
int code;
while (true) {
String input=null;
input = JOptionPane.showInputDialog("Please enter an integer");
if (input == "-1") {
//JOptionPane.showMessageDialog(null, input);
System.exit(0);
break;
} else {
if (input==null) {
System.exit(0);
} else if (input.isEmpty()) {
continue;
} else {
anInteger = Integer.parseInt(input);
code = this.oneGuess (anInteger);
//JOptionPane.showMessageDialog(null, anInteger);
}
}
}
}
我想,如果用户输入-1
,显示程序不会再提示消息框。以上是迄今为止我所提出的代码。为什么它不起作用?不能打破while循环
您正在等待您的代码中输入“1”来打破循环,而不是“-1” – evilone
输入错误............ – hkvega
我还建议您使用适合de的IDE发展(日食,netbeans等)cos编写==而不是.equals()shd向你显示警告,你可以纠正你自己。 –