public class Example{
static int right = (int)(Math.random()*100);
public static void main(String args[]){
in();
}
private static int in() {
int index = Integer.parseInt(JOptionPane.showInputDialog("請輸入:"));
for(;;){
if(index<right){
JOptionPane.showMessageDialog(null, "小了");
index = Integer.parseInt(JOptionPane.showInputDialog("請重新輸入:"));
}else{
if(index>right){
JOptionPane.showMessageDialog(null, "大了");
index = Integer.parseInt(JOptionPane.showInputDialog("請重新輸入:"));
}else{
JOptionPane.showMessageDialog(null, "恭喜妳答對了!!");
return 0;
}
}
}
}
}
這個只是簡單實現,這個程序只有在妳答對的情況下,才會退出,妳看看符合妳的要求不?