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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 安卓安小虾 中级黑马   /  2014-10-16 08:32  /  1375 人查看  /  9 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

              import java.util.Scanner;
class CaiShuZi{
                      public static void main(String[] args)
                       {
                                        int randomNumber =(int)(Math.random()*33)+1
                       Scanner sc=new Scanner(System.in);// 在键盘上输入一个33以内的随机数
                        while (true)// 开始了    输入你心中的数字吧
                        {
                                    System.out.print("请输入你要猜的数字");
                                     int enterNumber = sc.nextInt();//输入你要猜的数字
  
                          if (enterNumber>randomNumber)
                           {
                                       System.out.println("大了");//如果大了  继续
                           }else if (enterNumber<randomNumber)
                           {
                                        System.out.println("小了");//小了也继续
                           }else {
                                         System.out.println("恭喜你猜对了");
                                         break;
                              }
                    }
          }
}

评分

参与人数 1技术分 +1 收起 理由
杨佳名 + 1 赞一个!

查看全部评分

9 个回复

倒序浏览
12,12,12,12,12,12,12,
回复 使用道具 举报
不错啊!小游戏!
回复 使用道具 举报
不错,有想法,如果能结合个图形界面,打包好发出来就更好了~~
回复 使用道具 举报
楼主可以多加一个功能,设置可以猜多少次,没猜中就结束,这样会好玩一点!
回复 使用道具 举报
千里马 发表于 2014-10-17 00:10
楼主可以多加一个功能,设置可以猜多少次,没猜中就结束,这样会好玩一点! ...

嗯  好的 谢谢!!
回复 使用道具 举报

import java.util.Scanner;
class CaiShuZi{
       
   public static void main(String[] args)
        {
                int randomNumber =(int)(Math.random()*100)+1;                                              
                Scanner sc=new Scanner(System.in);// 在键盘上输入一个100以内的随机数
                        int count=0;//定义一个变量记录 输入了几次
                        while (count<5)// 开始了    输入你心中的数字吧  如果大于5次就输了
                   {
                          System.out.print("请输入你要猜的数字"+"\r\n");                          
                          int enterNumber = sc.nextInt();//输入你要猜的数字                                               
                     if (enterNumber>randomNumber)
                                      {
                                  System.out.println("大了"+"\r\n");
                                  count++;
                                  //如果大了  继续
                      }else if (enterNumber<randomNumber)
                                              {
                                   System.out.println("小了"+"\r\n");
                                   count++;//小了也继续
                      }else{
                                    System.out.println("恭喜你猜对了");                                    
                                    break;                          
                              }
             }  
                        System.out.println("你输错5次,请重新开始");       
     }
}
回复 使用道具 举报
哎呀 应该是  《=5 忘了加上去 !!
回复 使用道具 举报
嗯,这个不错哦。挺好的。谢谢楼主分享
回复 使用道具 举报
有想法。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马