Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+14 votes
asked in CSC211_Winter2018 by (1 point)

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 (1 point)
+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 (1 point)