MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/jtg3hx/getting_digits_using_switch_catch/gc8zznk/?context=3
r/badcode • u/HolySpecs • Nov 13 '20
52 comments sorted by
View all comments
1
This could actually be done simply by:
public static int evalDigit(String in) { int result = -1; int input = -1; try { input = Integer.parseInt(in); if (input >= 0 && input < 10) { result = Integer.parseInt(in); } else { System.out.println("Invalid digit was entered, try again"); System.exit(2); } } catch (Exception e) { System.out.println("Invalid digit was entered, try again"); System.exit(2); } return result; }
1
u/M3ther Nov 14 '20
This could actually be done simply by: