Просто сделайте бесконечный цикл вокруг части, которую вы хотите продолжать делать, пока не получите действительный ввод, и если вы получите действительный ввод, разбейте его.
while (true){
try {
double r = sc.nextDouble(); // Read in the double from the keyboard
double area = (3.14 *r * r);
String output = "Radius: " + r + "\n";
output = output + "Area: " + area + "\n";
System.out.println("The area of the circle is " + area);
break; <---- New code that will break the loop
}
catch( NumberFormatException e ) {
System.out.println("Invalid Input, please enter a number");
//put a message or anything you want to tell the user that their input was weird.
}
catch( InputMismatchException e )
{
System.out.println("Input Mismatch, please enter a number");
//put a message or anything you want to tell the user that there is an
//input mismatch.
}
}
The execution will continue from here after break