JAVA猜数字游戏源程序

  JAVA猜数字游戏源程序

  注册游戏账号点击图片进入游戏麻将赢牌技巧,打麻将技巧网,麻将技巧

  代码贴在下面,猜大小,还有猜多久出来的

  import java.util.Random;

  import java.util.Scanner;

  public class TestRandom

  {

      public static void main(String[] args)

      {

          Random r = new Random();

          int i;

          i = r.nextInt(10);

          System.out.println("请猜10以内的数字");

          long a=System.currentTimeMillis();

          while (true)

          {

              Scanner number = new Scanner(System.in);

              int f = number.nextInt();

              if (i > f)

              {

                  System.out.println("小了");

              } else if (i < f)

              {

                  System.out.println("大了");

              } else

              {

                  System.out.println("猜对了");

                  System.out.println("猜题用时 : "+(System.currentTimeMillis()-a)/1000f+" 秒 ");

                  break;

              }

          }

      }

  }

  JAVA猜数字游戏源程序

Comments

Popular posts from this blog

PNG黄金入场券游戏技巧,PNG黄金入场券游戏规则介绍

NBA中什么叫乐透区

PP亚特兰蒂斯女王游戏技巧,PP亚特兰蒂斯女王游戏规则介绍