nextInt方法,在发生异常时,不会接受用户再次输入的数据,而是徘徊在异常区域使用nextLine即可while(true){ System.out.println("请输入1个整数: "); try{ id = Integer.parseInt(input.nextLine().trim()); }catch(NumberFormatException nfe){ System.out.print("输入错误,"); continue; }}