CodePudding user response:
Written in the document clearlyPublic String nextLine ()
Advances this scanner past the current line and returns the input that was skipped. This method returns the rest of the current line, excluding any line separator at the end. The position is set to The beginning of The next line.
Since this method continues to search through the input & for a line separator, it may buffer all of the input the searching for the line to skip the if no line separators are present.
Netxline () will return the data before the newline (not including line breaks), but also move the pointer to the next line, although is also didn't read the newline character, but will skip it directly into the beginning of a line under the
As for the next (), nextint () will automatically filter out valid characters in front of the carriage return or Spaces such as invalid characters, look at the following example
Scanner sc=new Scanner (" ABC \ n \ n \ n \ n \ n \ n 456 123 789 ");
System. The out. Printf (" [% s], [% d], [% s], [% s] \ n ", sc. NextLine (), sc. NextInt (), sc. NextLine (), sc. The next ());
Nextint, next () () will be filtered out in front of the invalid characters, but after reading data will not automatically jump to the next valid character (that is, the back of the blank and return still stranded), and nextLine skips followed by a carriage return