package com.gds.demospring.testDemo;
import java.util.Random;
import java.util.Scanner;
/**
* @Author 龚道松
* @Date 2019/3/1 0001 19:17
* @Wersion 1.0
**/
public class RadomDemo01 {
public static void main(String[] args) {
// 获取随机数
Random r = new Random();
int number = r.nextInt(100);
while (true) {
// 键盘录入
Scanner sc = new Scanner(System.in);
// 接受数据
System.out.println("请输入数据(1-100): ");
int x = sc.nextInt();
// 判断是否是该数据
if (number > x) {
System.out.println("你输入的数字小了");
} else if (number < x) {
System.out.println("你输入的数字大了");
} else {
System.out.println("恭喜你猜中了");
break;
}
}
System.out.println("随机数是: " + number);
}
}