当前位置:网站首页>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、可以获得空白。
边栏推荐
- Multithreaded printing
- Druid monitoring statistics source
- 文件上传下载
- C # realize solving the shortest path of unauthorized graph based on breadth first BFS -- complete program display
- Redis tutorial
- Analyze datahub, a new generation metadata platform of 4.7K star
- gcc使用、Makefile总结
- ES6解构语法详解
- 如何校验两个文件内容是否相同
- How do spark tasks of 10W workers run? (Distributed Computing)
猜你喜欢

Cloud native annual technology inventory is released! Ride the wind and waves at the right time

Keil5中如何做到 0 Error(s), 0 Warning(s).
![[applet project development -- JD mall] uni app commodity classification page (first)](/img/6c/5b92fc1f18d58e0fdf6f1896188fcd.png)
[applet project development -- JD mall] uni app commodity classification page (first)

Metadata in NFT

数据交换 JSON

Chapter 03_ User and authority management

雪崩问题以及sentinel的使用

So easy 将程序部署到服务器

How to verify whether the contents of two files are the same

Druid monitoring statistics source
随机推荐
【小程序项目开发-- 京东商城】uni-app之分类导航区域
Feign远程调用和Getaway网关
STM32 - DS18B20 temperature sampling of first-line protocol
EtherCAT简介
访问url 404 的错误
XXL job User Guide
Is it safe to open an account online in a small securities firm? Will my money be unsafe?
C#实现图的深度优先遍历--非递归代码
Promise中finally的用法
Mybati SQL statement printing
串口接收数据方案设计
如何校验两个文件内容是否相同
Hal library setting STM32 interrupt
世界上最好的学习法:费曼学习法
multiple linear regression
MySQL index --01--- design principle of index
How to determine the progress bar loaded in the loading interface when opening the game
Force buckle - sum of two numbers
C language EXECL function
Redis分布式锁的8大坑