Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Hmm, why is the first one fine, but he second one causing an infinite loop when failing?
- // First one
- String number;
- int highestFactor;
- do
- {
- System.out.println("Please enter how high you'd like to multiply (up to 20): ");
- number = user_input.next();
- try {
- highestFactor = Integer.parseInt(number);
- } catch (NumberFormatException e) {
- System.out.print("That's not a number! ");
- highestFactor = -1;
- }
- } while (highestFactor <= 0 || highestFactor > MAX_FACTOR);
- // Second one
- int highestFactor;
- do
- {
- try {
- System.out.println("Please enter how high you'd like to multiply (up to 20): ");
- highestFactor = user_input.nextInt();
- } catch (InputMismatchException e) {
- System.out.print("That's not a number! ");
- highestFactor = -1;
- }
- } while (highestFactor <= 0 || highestFactor > MAX_FACTOR);
Advertisement
Add Comment
Please, Sign In to add comment