Scanner hasNextInt

原文链接: http://www.cnblogs.com/hellsino/p/11151303.html
import java.util.Scanner;

public class TestScanner {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num;
while (true) {
System.out.println("输入整型数字:");
if (in.hasNextInt()) {
num = in.nextInt();
break;
} else {
System.out.println("输入有误!");
in.next();
}
}
}
}

转载于:https://www.cnblogs.com/hellsino/p/11151303.html

猜你喜欢

转载自blog.csdn.net/weixin_30338481/article/details/95129269