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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© lijieping 中级黑马   /  2015-9-13 21:21  /  640 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

import java.util.Scanner;
class Test2_GuessNum {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                System.out.println("猜数字,范围在1-100");
                int guessNum = (int)(Math.random()*100) + 1;
                int count = 0;
        while (true){
                        int result = sc.nextInt();
                        if (result>guessNum){
                                System.out.println("大了");
                                count++;
                        }else if (result<guessNum){
                                System.out.println("小了");
                                count++;
                        }else {
                                System.out.println("中了");
                                count++;
                                break;
                        }
                }
                System.out.println(count);
                if (count == 1){
                        System.out.println("你的运气太好了,去买彩票去哇");
                }else if (count<10&&count>0){
                        System.out.println("你太聪明了");
                }else {
                        System.out.println(".......");
                }
        }
}

1 个回复

倒序浏览
已经收藏!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马