当前位置:网站首页>10、Scanner. Next() cannot read spaces /indexof -1

10、Scanner. Next() cannot read spaces /indexof -1

2022-07-01 03:35:00 weixin_ forty-seven million one hundred and twenty-seven thousa

Cause :

1. Use Scanner.next Get keyboard input name

2.name.indexOf by -1

answer :

next()

1、 Be sure to read valid characters before entering .

2、 Blank space before entering valid characters ,next() Method will automatically remove it .

3、 Only after entering a valid character, the space after it is used as a separator or terminator .

4、next() Cannot get string with space .

nextLine()

1、 With Enter End of character ,nextLine() Method returns all characters before entering carriage return .

2、 Can get blank .

原网站

版权声明
本文为[weixin_ forty-seven million one hundred and twenty-seven thousa]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/182/202207010313229926.html