My program takes in integer input, then a bigger integer input, then a string.
"Enter a number: "
"Enter a bigger number: "
"Enter a string: "
I was trying to use a try/catch to catch cases if a string was input instead of an integer. I sort of got the code to work, but after the error message executes it skips over the next int input question and goes straight to, "Enter a string."
I assume I need a while loop somewhere, but I'm having trouble figuring out where exactly to place it, and what argument to use. Simply put, (I think) I need: while (input != string). I just have no idea how to do that.
try {
System.out.println("Enter a number: ");
int start = myscanner.nextInt();
System.out.println("Enter a bigger number: ");
int end = myscanner.nextInt();
if (start > end) {
System.out.println("Error: Start should be smaller.");
} else {
int result = sumInt(start, end);
System.out.println("Result: " + result);
}
} catch (InputMismatchException exception) {
System.out.println("Enter a number, not a string.");
}
```````````````````````````````````````````````````````````````````````````