public class Demo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(true){
System.out.println("请输入一个整数:");
try{
int a = sc.nextInt();
System.out.println("你输入的数是:" + a);
break;
}catch(InputMismatchException e){
System.out.println("我让你输入的是整数!!");
sc = new Scanner(System.in);?为什么加这个?大神
}
}
System.out.println("程序结束......");
}
}
|
|