A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© ✦.灰机不会飞 中级黑马   /  2015-10-10 23:31  /  285 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

/*
* 需求:猜数字小游戏(数据在1-100之间)  对于次数进行计数并且对次数进行评价
*/
import java.util.Scanner;
class Test_Math {
        public static void main(String[] args) {
                int count = 0;
                Scanner sc = new Scanner(System.in);
                System.out.println("请输入一个1-100的整数");
                int x = (int)(Math.random() * 100) + 1;       
                        while (true) {
                                int y =sc. nextInt();
                                count++;
                                if (y > x ) {
                                        System.out.println("大了");
                                }
                                else if (y < x ) {
                                        System.out.println("小了");
                                }
                                else{
                                System.out.println("中了");
                                if (count < 5) {
                                        System.out.println("牛逼");
                                }
                                else if (count >= 5 && count <= 8) {
                                        System.out.println("就那样");
                                }else{
                                        System.out.println("菜鸟");
                                }
                                break;

                                }
                        }
                        System.out.println(count);
        }
}

1 个回复

倒序浏览
有点意思 算是最容易做的游戏了?
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马