import javax.swing.JOptionPane; public class 图形化{ /** * 猜数字游戏 */ public static void main(String[] args) { // TODO Auto-generated method stub do{ int r = (int)(100 * Math.random()); int guess; JOptionPane.showMessageDialog(null, "猜猜看游戏,系统产生了一个100以内的随机整数,请输入你猜到的数字."); int count = 1; do{ String guessStr = JOptionPane.showInputDialog("第" + count + "次猜:"); guess = Integer.parseInt(guessStr); if(guess > r){ JOptionPane.showMessageDialog(null, "/t/t你猜的数字太大了,再小点!"); }else if(guess < r){ JOptionPane.showMessageDialog(null, "/t/t你猜的数字太小了,再大点!"); }else{ if(count < 5){ JOptionPane.showMessageDialog(null, "你太有才了,猜对了!"); }else if(count < 10){ JOptionPane.showMessageDialog(null, "还算不错,你猜了" + count +"次就猜出来了!"); }else{ JOptionPane.showMessageDialog(null, "你有点笨,猜了" + count +"次才猜出来!"); } } count++; }while(guess != r); }while(JOptionPane.showConfirmDialog(null, "你还想玩吗?")==0); } }