public class Homework21 {
public static void main(String[] args) {
Random rand = new Random();
Scanner sc = new Scanner(System.in);
int num = rand.nextInt(100) + 1;
int t = 0;
while (true) {
public static void main(String[] args) {
Random rand = new Random();
Scanner sc = new Scanner(System.in);
int num = rand.nextInt(100) + 1;
int t = 0;
while (true) {
System.out.println("请输入1-100之间的整数:");
try {
t = sc.nextInt();
} catch (InputMismatchException e) {
System.out.println("输入有误!请重新输入");
sc.next();
continue;
}
if (t < num) {
System.out.println("太小了!");
} else if (t > num) {
System.out.println("太大了!");
} else {
System.out.println("恭喜你,答对了!");
break;
}
}
}
}
try {
t = sc.nextInt();
} catch (InputMismatchException e) {
System.out.println("输入有误!请重新输入");
sc.next();
continue;
}
if (t < num) {
System.out.println("太小了!");
} else if (t > num) {
System.out.println("太大了!");
} else {
System.out.println("恭喜你,答对了!");
break;
}
}
}
}