码迷,mamicode.com
首页 > 其他好文 > 详细

Scanner hasNextInt

时间:2019-07-08 15:18:52      阅读:92      评论:0      收藏:0      [点我收藏+]

标签:输入   main   rgs   public   exti   util   scanner   ann   整型   

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();
}
}
}
}

Scanner hasNextInt

标签:输入   main   rgs   public   exti   util   scanner   ann   整型   

原文地址:https://www.cnblogs.com/hellsino/p/11151303.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!