Hello all, I'm working on a homework assignment involving recursion. The problem is I can't get to the recursion part because I've run into an IO problem that I can't figure out for the life of me. The whole point of the lab is doing Recursion for a binary search and I don't want help with that. I have run into a problem with getting the height/width of a rectangle from the user. If the user inputs a letter/character and not a number I get an infinite loop that is displayed as a result of catching an InputMismatchException. If anyone can give me some advice or point me in the right direction as how to fix this issue, I would greatly appreciate it.
Below is the method causing the error.
public static Rectangle getRectangle()
Scanner keyboard = new Scanner (System.in);
Rectangle r = new Rectangle();
System.out.print("Enter the height of the rectangle: ");
r.height = keyboard.nextInt();
catch (InputMismatchException e)
System.out.println("You didn't enter a number. You must enter a positive integer.");
if (r.height <= 0)
System.out.println("You must enter a positive integer.");
System.out.print("Enter the width of the rectangle: ");
r.width = keyboard.nextInt();