What does scanner.nextLong() do?

Prepare for the Computer Programming Test. Dive into a world of coding with multiple choice questions, flashcards, and detailed explanations. Boost your knowledge and be exam-ready!

Multiple Choice

What does scanner.nextLong() do?

Explanation:
Reading a 64-bit integer from input, using the Scanner. This method grabs the next token of input (whitespace-delimited), then parses it as a long, which is Java’s 64-bit signed integer, and returns that value. If the next token isn’t a valid long (for example, it contains letters or a decimal point, or the value is outside the long range), an exception is thrown. It can also throw if there’s no more input or if the scanner is closed. So, this is distinct from methods that read other types: reading a 32-bit int, a 32-bit float, or a 64-bit double would use different methods designed for those types.

Reading a 64-bit integer from input, using the Scanner. This method grabs the next token of input (whitespace-delimited), then parses it as a long, which is Java’s 64-bit signed integer, and returns that value. If the next token isn’t a valid long (for example, it contains letters or a decimal point, or the value is outside the long range), an exception is thrown. It can also throw if there’s no more input or if the scanner is closed.

So, this is distinct from methods that read other types: reading a 32-bit int, a 32-bit float, or a 64-bit double would use different methods designed for those types.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy