package main; import java.util.Random; import java.util.Scanner; public class Test { public static void main(String[] args) { Random r = new Random(); int range = r.nextInt(100)+1; Scanner sc = new Scanner(System.in); while (true){ System.out.println("请输入猜测的数字:"); int digital = sc.nextInt(); if (digital > range){ System.out.println("您猜测的数字太大了!"); }else if(digital < range){ System.out.println("您猜测的数字太小了!"); }else { System.out.println("恭喜您猜中了!"); break; } } } }