大家好,又见面了,我是你们的朋友全栈君。
在java中有一种类可以获取我们输入的信息,这也是java中的新特征,有小伙伴知道这是什么类吗?小编最近在学Scanner类,发现还需要结合正则表达式一起使用,这对我们以前知识的掌握来说,得有比较好的基础才能完成。下面我们就一起看看Scanner类如何在java中使用吧。
1.概念
一个可以使用正则表达式来解析基本类型和字符串的简单文本扫描器。
2.语法Scanner s = new Scanner(System.in);
3.普通方法
next():扫描一行输入,遇到空格/换行符才结束扫描。
nextLine():扫描一行输入,遇到换行符结束扫描。
nextInt():扫描一行输入,得到一个Int类型值。
hasNext():Returns true if this scanner has another token in its input. This method may block while waiting for input to scan. The scanner does not advance past any input.(当执行该方法时,会有堵塞现象,待用户输入时,遇到空格或换行符则返回true)
hasNextLine():Returns true if there is another line in the input of this scanner. This method may block while waiting for input. The scanner does not advanc
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/162021.html原文链接:https://javaforall.cn
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有