package com.gaoce;import java.util.Random;
import java.util.Scanner;public class GuessNumber {Random random = new Random();public int random_value = genRandom();public void resetRandom() {random_value = genRandom();}private int genRandom() {return random.nextInt(10) + 1;}public static void main(String[] args) {GuessNumber getRandom = new GuessNumber();Scanner scanner = new Scanner(System.in);System.out.print("请猜数字(1-10): ");while (true) {int number = getRandom.random_value;int input = scanner.nextInt();if (input == number) {System.out.println("正确");System.out.print("是否继续(0-退出 1-继续): ");int input1 = scanner.nextInt();if (input1 == 0) {System.out.println("游戏结束");break;} else {getRandom.resetRandom();System.out.println("游戏继续(已更换随机数)");System.out.print("请猜测: ");continue;}} else if (input < number) {System.out.println("小了");} else {System.out.println("大了");}System.out.print("请继续加油: ");}}
}