protected int readInt(String prompt) {
try {
System.out.print(prompt);
int i = keyboard.nextInt();
keyboard.nextLine();
return i;
} catch (java.util.InputMismatchException e) {
System.out.println("Error: Insert a number.");
}
}
Hi! Eclipse gives me this error at the method readInt(): "This method must return a result of type int." and gives the example solutions "Add return statement" and "Change return type to void". I've tried to put the return i statement outside the try-and-catch loop, but when I do, the return statement can't find the variable i.
I've been struggeling with this for a while now, and can't seem to make it work... I would appreciate any help! Thank you.