给你一个我写的吧,但和你的要求有一点出入,你自己在修改一下以便达到你的要求:
import javax.swing.JOptionPane;
public class guess {
public static void main(String[] args) {
String output = "";
int count = 0;
int n = (int) (10 + 90 * Math.random());
for (int i = 1; i <= 100; i++) {
count++;
String number = JOptionPane
.showInputDialog("Please input the answer !");
int m = Integer.parseInt(number);
if (m <= 0 || m >= 100) {
output = "Please an integer 10-99 !";
} else if (m < n) {
output = "输入的值小于实际值!";
} else if (m > n) {
output = "输入的值大于实际值!";
} else {
output = "恭喜你答对了!您的最准分数为:" + (110-count*10);
JOptionPane.showMessageDialog(null, output);
break;
}
JOptionPane.showMessageDialog(null, output);
}
}
}