public void runMenu() { int x = 1; Scanner Option = new Scanner(System.in); int Choice = 0; do { try { System.out.println("Choose Option"); System.out.println(""); System.out.println("1: Create Account"); System.out.println("2: Check Account"); System.out.println("3: Take Action"); System.out.println("4: Exit"); System.out.println("Please choose"); Choice = Option.nextInt(); switch (Choice) //used switch statement instead of If else because more effective { case 1: CreateAccount(); break; //breaks iteration case 2: selectAccount(); break; case 3: break; } } catch (Exception e) { System.out.println("Cant do that"); } } while (Choice < 4); System.out.println("Bye"); } The exception handling doesnt work e.g. if I enter say outide the range such as 5 it should say something like "Cant do that". Should I enter a if statement defining the condition if so how can I go about doing that? right now it just prints "Bye" if I enter wrong key.
default:case of the switch. (Whether using exceptions here in the first place is correct is debatable)breakapplies to the switch; not the loop..nextInt()will try and grab any valid integer from the input. 5 is valid...