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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© Lingxin 中级黑马   /  2016-3-26 23:32  /  472 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. import java.util.Scanner;
  2. class Test1_GuessNum {
  3.         public static void main(String[] args) {
  4.                 Scanner sc = new Scanner(System.in);                       
  5.                 System.out.println("请输入一个整数,范围在1-100之间");
  6.                 int guessNum = (int)(Math.random() * 100) + 1;       
  7.                 while (true) {                                       
  8.                         int result = sc.nextInt();                       
  9.                         if (result > guessNum) {                       
  10.                                 System.out.println("大了");               
  11.                         } else if (result < guessNum) {               
  12.                                 System.out.println("小了");       
  13.                         } else {                               
  14.                                 System.out.println("中了");       
  15.                                 break;
  16.                         }
  17.                 }
  18.         }
  19. }
复制代码



当作娱乐,课间放松亲们

1 个回复

正序浏览
猜数字的小游戏啊
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马