代码如下:

package day05;

import java.util.Random;
import java.util.Scanner;

// 猜数字游戏
public class RandomGame {
    public static void main(String[] args) {
        Random random = new Random();
        Scanner scanner = new Scanner(System.in);
        int num = random.nextInt(100) + 1;
        System.out.println("随机产生的数字是:" + num);
        while (true) {
            System.out.print("请输入数字:");
            int inputNumber = scanner.nextInt();
            if (num == inputNumber) {
                System.out.println("猜对了,游戏结束");
                break;
            } else if (inputNumber > num) {
                System.out.println("输入数字大了");

            } else {
                System.out.println("输入数字小了");
            }
        }

    }
}