The first loop in the second method works perfectly. when the user inputs characters instead of numbers the InputMismatchException is caught and the user is prompted to re-enter numbers only in order to continue. The second loop fails: If characters are entered for the next question, the InputMismatchException is caught and "...please try again" is displayed but then the program continues on without forcing the user to re-enter numbers. Is it possible to have more than 1 do/while, try/catch for an InputMismatchException within 1 method? I have no idea what I am doing wrong. I think I am right in theory but obviously not! How can I fix this without separating into different methods (because then my method for calculations won't work)?
{
Scanner input = new Scanner( System.in );
boolean continueLoop = true;
do{
System.out.print("\nPlease enter weight");
try{
stone = input.nextInt();
while (...)
{
System.out.print("...");
stone = input.nextInt();
}
continueLoop = false;
}
catch ( InputMismatchException inputMismatchException)
{
System.err.printf( "\nException: %s\n",
inputMismatchException );
input.nextLine();
System.out.println("...Please try again.\n" );
}
}while ( continueLoop );
do{
System.out.print("...");
try{
pounds = input.nextDouble();
while (...)
{
System.out.print("...");
pounds = input.nextDouble();
}
continueLoop = false;
}
catch ( InputMismatchException inputMismatchException)
{
System.err.printf( "\nException: %s\n",
inputMismatchException );
input.nextLine();
System.out.println("..." );
}
}while ( continueLoop ); //code continues more methods...