public static void main(String[] args) { guess(); } private static void guess(){ Scanner sc = new Scanner(System.in); //获取Ranfom集合 Random random = new Random(); int randomNumber = random.nextInt(100); while(true){ System.out.print("请随便输入:"); int inputNumber = sc.nextInt(); if(inputNumber>randomNumber){ System.out.println("猜大了,请重猜"); }else if(inputNumber<randomNumber){ System.out.println("猜小了,请重猜"); }else{ System.out.println("恭喜你猜对了,游戏结束"); break; } } }