首页 > 其他 > 详细

hasNextInt()方法

时间:2017-07-24 22:05:17      阅读:145      评论:0      收藏:0      [点我收藏+]

hasNextInt()方法是判断控制台接收是否为数字,当你在控制台输入一个字符的时候,hasNextInt()判断你输入这个字符是不是数字,而不是接收值,当if判断通过之后执行接收,也就是你输入的那个字符,你也可以试试 public static void main(String[] args) { Scanner input = new Scanner(System.in); if(input.hasNextInt()){ int num = input.nextInt(); System.out.println(num); }else{ System.out.println("请输入正确数字!~"); } } 当你输入非数字的字符的时候他会直接进入else块,所以说hasNextInt()只起到判断作用而不是接收数据

hasNextInt()方法

原文:http://www.cnblogs.com/jmsjh/p/7231227.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!