···java
import java.util.Random;
import java.util.Scanner;
public class X24 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Random r = new Random();
int num1 = r.nextInt(100) + 1;
System.out.println("数字炸弹游戏开始:");
System.out.println("猜数,请输入要猜得数字:");
int num2 = in.nextInt();
while (num1 != num2) {
if(num2>num1){
System.out.println("猜大了");
}else{
System.out.println("猜小了");
}
System.out.println("数字炸弹游戏开始:");
System.out.println("猜数,请输入要猜得数字:");
num2 = in.nextInt();
}
System.out.println("恭喜您猜中了!");
}
}
···