import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("输入x:");
String x;
do {
try {
x = sc.nextLine();
if (Integer.valueOf(x) instanceof Integer) {
System.out.println("输入为整数,程序结束.");
break;
} else {
x = sc.nextLine();
}
} catch (Exception e) {
System.out.println("请输入整数.");
}
} while (true);
}
}
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/279759ee3d6d55fbc6f7fedd69224f4a20a4dd1c?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)