Javier Bolanos
Javier Bolanos

Reputation: 7

Scanner Input: Throwing NoSuchElementException

Why does Java accept 1234567891 as input but not 987654321 ? I keep getting NoSuchElementException, and I am just wondering why the error.

Upvotes: 0

Views: 67

Answers (1)

Niranjan Kumar
Niranjan Kumar

Reputation: 1518

Range of 4 byte integer in Java is –2,147,483,648 to 2,147,483,647

Thus it won't be able to accept 987654321 in scanner.getInt();

To accept the above mentioned value , use scanner.getLong()

Upvotes: 2

Related Questions