Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+14 votes
asked in CSC211_Winter2018 by (8 points)

2 Answers

+13 votes

nextInt() returns an integer from the input. hasNextInt() returns true/false for whether the next input is an legal integer or not. It would return false if you typed a string, character or integer beyond the MAX_VALUE for integers.

answered by (8 points)
+9 votes

input.hasNextInt(); is useful for while loops as it allows you to check if the file you are reading has another int which keeps the while loop running. input.nextInt() on the other hand actually reads the next integer in the file.

answered by (8 points)
...