package com.example.controller;
import java.util.Random;
import java.util.Scanner;
public class CaiDemo {
public static void main(String[] args) {
Random random = new Random();
int num = random.nextInt(101); //0~100
while (true) {
Scanner scanner = new Scanner(System.in);
System.out.println("============================");
System.out.println("请输入你要的数字:");
int guessNum = scanner.nextInt();
if(guessNum > num){
System.out.println("你猜的数字:"+guessNum+ " 大了");
}else if(guessNum < num){
System.out.println("你猜的数字:"+guessNum+ " 小了");
}else {
System.out.println("恭喜你猜中了");
break;
}
}
}
}
?
|