当前位置: 代码迷 >> Java相关 >> 猜数游戏
  详细解决方案

猜数游戏

热度:99   发布时间:2010-07-01 23:50:55.0
猜数游戏
要求完成:
(1)    游戏开始后,随机产生四个1-10之间的不同数,作为游戏数答案
(2)    用户每次给出4个数,该软件给出正误(某个数位置正确、数值正确则显示一个A;数值正确,位置不正确显示一个B);将用户猜测的数的正误统计出来给用户,以备继续游戏;直到用户猜出所有四个数,给出用户猜测出正确时游戏的次数。
(3)    使用界面完成


急用,在线等。
搜索更多相关的解决方案: 游戏  

----------------解决方案--------------------------------------------------------
给你一个我写的吧,但和你的要求有一点出入,你自己在修改一下以便达到你的要求:
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);
        }
    }
}
----------------解决方案--------------------------------------------------------
  相关解决方案