当前位置:网站首页>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、可以获得空白。
边栏推荐
- 打包iso文件的话,怎样使用hybrid格式输出?isohybrid:command not found
- mybati sql 语句打印
- Introduction and installation of Solr
- shell脚本使用两个横杠接收外部参数
- 线程数据共享和安全 -ThreadLocal
- gcc使用、Makefile总结
- EtherCAT简介
- Common interview questions for performance test
- Cookie&Session
- [applet project development -- Jingdong Mall] user defined search component of uni app (Part 1)
猜你喜欢
随机推荐
Introduction and basic knowledge of machine learning
[exsi] transfer files between hosts
Pytest -- plug-in writing
Metadata in NFT
别再说不会解决 “跨域“ 问题啦
Nacos
Example of Huawei operator level router configuration | example of configuring optionc mode cross domain LDP VPLS
How to verify whether the contents of two files are the same
Go tool cli for command line implementation
IEDA 右键源码文件菜单简介
Completely solve the lost connection to MySQL server at 'reading initial communication packet
[small program project development -- Jingdong Mall] the home page commodity floor of uni app
岭回归和lasso回归
【小程序项目开发-- 京东商城】uni-app之分类导航区域
Introduction to ieda right click source file menu
Edge Drawing: A combined real-time edge and segment detector 翻译
C language EXECL function
过滤器 Filter
Ctfshow blasting WP
Hal library operation STM32 serial port









