首页 > 其他 > 详细

随堂练习——猜生日

时间:2016-03-02 12:45:03      阅读:85      评论:0      收藏:0      [点我收藏+]
 1   Scanner sc=new Scanner(System.in);
 2         System.out.println("请猜一下我的生日(1~31):");
 3         int a=sc.nextInt();
 4         int b=15;        
 5         while(b!=a)
 6         {
 7             if(a>b&&a<=31)
 8             {
 9             System.out.println("生日猜大了,请继续猜:");
10              a=sc.nextInt();
11             }
12             else if(a>=1&&a<b)
13             {
14                 System.out.println("生日猜小了,请继续猜:");
15                 a=sc.nextInt();
16             }
17                 else
18                 {
19                     System.out.println("请输入所给的范围:");
20                     a=sc.nextInt();
21                 }                         
22         }        
23         System.out.println("猜对了!");

则运行结果为:

技术分享

随堂练习——猜生日

原文:http://www.cnblogs.com/hanazawalove/p/5234194.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!