In pseudo code:
loop until good data type
Ask user for data
use hasNext to test if desired data type ready to be read
if it is, exit the loop
Use nextLiine() to read in the wrong data
Tell user...
Type: Posts; User: Norm
In pseudo code:
loop until good data type
Ask user for data
use hasNext to test if desired data type ready to be read
if it is, exit the loop
Use nextLiine() to read in the wrong data
Tell user...
Another approach is to use some of Scanner class's hasNext... methods. You can ask the Scanner object if the next thing in its buffer to be read is an int by using the hasNextInt() method. If what's...
Another problem with using Scanner is that the invalid data is still in the buffer. The next nextInt() call will again try to make an int and will fail. You need to clear what is in the buffer...