随堂练习——猜生日
2016-03-02 11:19
204 查看
Scanner sc=new Scanner(System.in); System.out.println("请猜一下我的生日(1~31):"); int a=sc.nextInt(); int b=15; //可以用final来把b定义成常量 while(b!=a) { if(a>b&&a<=31) { System.out.println("生日猜大了,请继续猜:"); a=sc.nextInt(); } else if(a>=1&&a<b) { System.out.println("生日猜小了,请继续猜:"); a=sc.nextInt(); } else { System.out.println("请输入所给的范围:"); a=sc.nextInt(); } } System.out.println("猜对了!"); sc.close(); //这表示清除内存
则运行结果为:
相关文章推荐
- 做市场的人,不一定知道什么才是“市场”
- 打印1到最大的n位数
- 0302思考&回答
- 为什么MVC不是23中设计模式之一?
- DrawerLayout 抽屉菜单效果使用实例介绍
- nginx 跳转指定接口
- Postgres-XL 9.5 R1 (Beta 1) 编译
- javascript里的DOM和BOM
- Eclipse的Local History保存位置
- usb更新文件
- noitatoNhsiloPesreveRetaulavE.150
- 排序算法之归并排序
- JSP默认HTML4改为HTML5
- android studio1.4新建工程运行出错
- 二叉树的构建以及先中后序遍历
- ArcGIS教程:设置地理处理环境
- 1059. Prime Factors (25)
- discuzX 3.1/2 如何重新安装
- QtGui继承关系树
- c++ 思考