黑马程序员技术交流社区

标题: 猜数字游戏 [打印本页]

作者: 251855915    时间: 2016-4-7 23:11
标题: 猜数字游戏
  1. import java.util.Scanner;
  2. class Guess {
  3.         public static void main(String[] args)  {
  4.                 Scanner sc = new Scanner(System.in);
  5.                 int x = (int)(Math.random()*100+1);
  6.                 System.out.println("我在心里想了一个1--100之间的数字,请你猜一猜,在下面输入你猜的数字吧");
  7.                
  8.                 while (true) {
  9.                         int i = sc.nextInt();
  10.                         if (i>x) {
  11.                                 System.out.println("大了");
  12.                         }
  13.                         else if (i<x) {
  14.                                 System.out.println("小了");
  15.                         }
  16.                         else {
  17.                                 System.out.println("猜中啦");
  18.                                 break;
  19.                         }
  20.                 }
  21.         }
  22. }
复制代码

这个游戏怎么改动可以让人们选择是否继续再玩一次呢?
作者: yy0328    时间: 2016-4-7 23:23
同学你好,同学再见
作者: kuro    时间: 2016-4-7 23:39
http://bbs.itheima.com/thread-289726-1-1.html   我写的,一起讨论下
作者: RonaldoYang    时间: 2016-4-8 01:59
哈哈哈,,,牛逼。。。顶你
作者: 轰天雷    时间: 2016-4-8 07:42
顶起来赞
作者: 兵蜂    时间: 2016-4-8 08:23
赞赞!!!!!




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2