No, I don't recommend that. There is one situation where a nestLine() call is needed. See this old post of mine.
William Varner wrote:Also, do y'all recommend doing a "sc.nextLine()" after scanning in an int? I was taught that this was very important.
JavaDocs of nextLine() wrote:* This method returns the rest of the current line, excluding any line
* separator at the end. The position is set to the beginning of the next
Since there is nothing else to read, end of story, exception would be thrown attempting to read further.
JavaDocs of nextLine() wrote:* The position is set to the beginning of the next line.
It won't. It will throw an exception. If you want to avoid the exception, you need the loop which Rob Spoor taught me ages ago:-I have that method overloaded so as to accept different error messages for incorrect input. I also have the method overloaded to accept only values in a certain range, but you have to throw an illegal argument exception if !(max > min). I have not therefore worked out how to supply a default. Lines 21‑22 can be swapped.
Knute Snortum wrote:. . . . I don't want the program to accept 6 and leave e in the buffer. I want the program to ask for the age again. . . . .