Issue Notes-1: next() and nextLine()

About myself in the process of practicing the first song

I am practicing on the idea

For example this question:

EduCoder Java programming variables and data types Level 7: The use of Scanner _m0_63324772's blog-CSDN blog https://blog.csdn.net/m0_63324772/article/details/123407151?spm=1001.2014.3001.5501 Do it yourself in idea first Okay, but if you input the original idea in the header song as it is, you will get an error

It turned out to be this problem:

Questions about next and nextline

When the next() method reads the content, it will filter out the invalid characters before the valid characters, and the next() method will automatically filter out the terminators such as the space bar, Tab key or Enter key encountered before the valid characters are input. ; Only after a valid character is read, the next() method treats the space bar, Tab key or Enter key after it as a terminator; so the next() method cannot get a string with spaces.

The nextLine() method literally means scanning an entire line, and its terminator can only be the Enter key, that is, the nextLine() method returns all characters that have not been read before the Enter key, and it can get spaces with spaces string.

 In this code, due to the problem of nextLine, I have also new a lot of objects, and this method cannot be run on the first song. It may be due to the problem of the first song detection mechanism, and then an error is reported or it does not conform to the output format.

for example:

 

I feel better after the correction

Borrow a blog to explain:

 

Oh well, problem solved!

Supongo que te gusta

Origin blog.csdn.net/m0_63324772/article/details/123407475
Recomendado
Clasificación