import java.util.Random;
import javax.swing.JOptionPane;
public class GuessNumber{
public static void main(String[]args){
//TODO Auto-generated method stub
int start=JOptionPane.showConfirmDialog(null,"猜数字,游戏开始?","游戏开始",JOptionPane.YES_NO_CANCEL_OPTION);
if(start==JOptionPane.YES_NO_OPTION){
int num=(new Random().nextInt(100));
String inputValue;//保存用户输入字符串
int inputuNum;//保存字符串转换的整数
int i=1;//记录猜数的次数
while(i<=8){
inputValue=JOptionPane.showInputDialog("请输入一个0^100的整数\n,共8次机会,这是第"+i+"次");
int inputNum=Integer.parseInt(inputValue);
if(inputNum==num){
JOptionPane.showMessageDialog(null,"恭喜您,猜对啦!","猜数字游戏",RMATION_MESSAGE);
break;
}
else if(inputNum>num)
JOptionPane.showMessageDialog(null,"您猜的数字偏大!","猜数字游戏",JOptionPane.WARNING_MESSAGE);
else
JOptionPane.showMessageDialog(null,"您猜的数字偏小!","猜数字游戏",JOptionPane.WARNING_MESSAGE);
i++;
}
if(i>8)
JOptionPane.showMessageDialog(null,"8次机会用尽,游戏结束!","游戏结束",JOptionPane.ERROR_MESSAGE);
}
else
JOptionPane.showMessageDialog(null,"退出游戏","猜数字游戏",RMATION_MESSAGE);
} }。