当前位置:网站首页>10、Scanner.next() 无法读取空格/indexOf -1
10、Scanner.next() 无法读取空格/indexOf -1
2022-07-01 03:13:00 【weixin_47127217】
原由:
1.使用Scanner.next获取键盘输入 name
2.name.indexOf 为-1
解答:
next()
1、一定要读取到有效字符后才可以输入。
2、对输入有效字符之前的空白,next()方法会自动将它去掉。
3、只有输入有效字符后才将其后面的空白作为分隔符或结束符。
4、next()不能得到带有空格的字符串。
nextLine()
1、以Enter为结束符,nextLine()方法返回的是输入回车之前的所以字符。
2、可以获得空白。
边栏推荐
- [linear DP] longest common subsequence
- 过滤器 Filter
- Introduction to ieda right click source file menu
- [small program project development -- Jingdong Mall] the home page commodity floor of uni app
- IEDA 右键源码文件菜单简介
- The value of the second servo encoder is linked to the NC virtual axis of Beifu PLC for display
- Depth first traversal of C implementation Diagram -- non recursive code
- 手把手带你了解一块电路板,从设计到制作(干货)
- Chapter 03_ User and authority management
- JUC学习
猜你喜欢
随机推荐
Introduction to webrtc concept -- an article on understanding source, track, sink and mediastream
Go tool cli for command line implementation
POI导出excel,按照父子节点进行分级显示
[QT] add knowledge supplement of third-party database
VMware vSphere 6.7虚拟化云管理之12、VCSA6.7更新vCenter Server许可
Latest interface automation interview questions
终极套娃 2.0 | 云原生交付的封装
pytest-fixture
Cookie&Session
Subnet division (10)
The shell script uses two bars to receive external parameters
Keil5中如何做到 0 Error(s), 0 Warning(s).
JUC learning
Detailed list of errors related to twincat3 ads of Beifu
Redis高效点赞与取消功能
【读书笔记】《文案变现》——写出有效文案的四个黄金步骤
[us match preparation] complete introduction to word editing formula
Subnet division and subnet summary
gcc使用、Makefile总结
Lavaweb [first understanding the solution of subsequent problems]









