Scanner.hasNextInt()返回
true下一个标记是否为数字,
false否则返回。
在此示例中,我调用hasNextInt()。如果返回
true,我将经过一会儿并设置输入;如果返回
false,则放弃输入(
scanner.next();)并重复。
Scanner scan = new Scanner(System.in);while(!scan.hasNextInt()) { scan.next();}int input = scan.nextInt();
Scanner.hasNextInt()返回
true下一个标记是否为数字,
false否则返回。
在此示例中,我调用hasNextInt()。如果返回
true,我将经过一会儿并设置输入;如果返回
false,则放弃输入(
scanner.next();)并重复。
Scanner scan = new Scanner(System.in);while(!scan.hasNextInt()) { scan.next();}int input = scan.nextInt();