+ 1

In java exception handling how can i loop it back

In java exception handling how can i loop it back so that i can take correct input again if like for example input mismatch exception were to happen

5th Mar 2019, 2:29 PM
Sol Tig
Sol Tig - avatar
1 Odpowiedź
+ 3
Use do-while as below do { try { System.out.print("Enter the number of students: "); students = input.nextInt(); } catch (InputMismatchException e) { System.out.print("Invalid number of students. "); } input.nextLine(); // clears the buffer } while (students <= 0);
5th Mar 2019, 2:45 PM
Prokopios Poulimenos
Prokopios Poulimenos - avatar