Quantcast
Viewing latest article 3
Browse Latest Browse All 485

Answer by Federico klez Culloca for Why there is no scanner.nextline() method between two nextInt() methods

nextInt reads the next token in the scanner.

According to the documentation

A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace.

And further down

The default whitespace delimiter used by a scanner is as recognized by Character.isWhitespace().

The documentation for Character.isWhitespace() says that it returns true if the given codepoint

[...][...] is '\n', U+000A LINE FEED.[...]

Which means that \n is a separator, thus it's not part of any token, so you don't need to skip it with a dummy call to nextLine()


Viewing latest article 3
Browse Latest Browse All 485

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>