package text; import java.util.Random; import java.util.Scanner; public class Work { public static void main(String[] args) { Random ran = new Random(); int y = ran.nextInt(100) + 1; int x = 0; int num =0; Scanner in = new Scanner(System.in); do { num++; boolean b = true; System.out.println("游戏开始请输入整数:"); while (b) { try { x = in.nextInt(); b = false; } catch (Exception e) { System.out.println("输入错误,请重新输入:"); in.nextLine();//读入回车符,确保循环可以正常进行 } } if (x > y) { System.out.println("太大了3"); } else if (x < y) { System.out.println("太小了"); } } while (x != y); int score = 100 - (num - 1)*10; System.out.println("恭喜你猜对了,您的分数为:" + score); } }