当前位置:网站首页>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、可以获得空白。
边栏推荐
- Huawei operator level router configuration example | configuration static VPLS example
- Mybati SQL statement printing
- JUC学习
- [linear DP] longest common subsequence
- Hello World generation
- How to verify whether the contents of two files are the same
- The best learning method in the world: Feynman learning method
- 最新接口自动化面试题
- Introduction to ieda right click source file menu
- JS daily development tips (continuous update)
猜你喜欢

Cookie&Session

C语言多线程编程入门学习笔记

Let's just say I can use thousands of expression packs

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

岭回归和lasso回归

Redis tutorial
![[linear DP] shortest editing distance](/img/2f/9a6f661bf478fdd5d53e5a03d7297d.jpg)
[linear DP] shortest editing distance
![[small program project development -- Jingdong Mall] the home page commodity floor of uni app](/img/80/20bed20a6ab91e82ad6800b11f2caa.png)
[small program project development -- Jingdong Mall] the home page commodity floor of uni app

第03章_用戶與權限管理

HTB-Lame
随机推荐
打包iso文件的话,怎样使用hybrid格式输出?isohybrid:command not found
If a parent class defines a parameterless constructor, is it necessary to call super ()?
Hal library operation STM32 serial port
监听器 Listener
STM32 - DS18B20 temperature sampling of first-line protocol
JS to find duplicate elements in two arrays
leetcode 1482 猜猜看啊,这道题目怎么二分?
别再说不会解决 “跨域“ 问题啦
如何校验两个文件内容是否相同
How do spark tasks of 10W workers run? (Distributed Computing)
md5sum操作
倍福TwinCAT3 Ads相关错误详细列表
过滤器 Filter
JS日常开发小技巧(持续更新)
Introduction to core functions of webrtc -- an article on understanding SDP PlanB unifiedplan (migrating from PlanB to unifiedplan)
split(),splice(),slice()傻傻分不清楚?
EtherCAT原理概述
Pytest -- plug-in writing
How to achieve 0 error (s) and 0 warning (s) in keil5
[linear DP] shortest editing distance