输入非整数时,对的
Scanner调用
nextInt()不会消耗非整数。您需要致电
keyboard.next()(或
keyboard.nextLine())使用它。就像是,
try { dim = keyboard.nextInt();} catch (Exception e) { System.out.printf("%s is not an integer.%n", keyboard.next()); err = 1;}
输入非整数时,对的
Scanner调用
nextInt()不会消耗非整数。您需要致电
keyboard.next()(或
keyboard.nextLine())使用它。就像是,
try { dim = keyboard.nextInt();} catch (Exception e) { System.out.printf("%s is not an integer.%n", keyboard.next()); err = 1;}