0

How do i make the user input loop until the input is valid?

Scanner input = new Scanner(System.in); String jobselect; int x = 0; do{ jobselect = input.next(); switch(jobselect){ case "pld": Paladin pld = new Paladin(); pld.sheet(); x += 1; break; case "gla": Gladiator gla = new Gladiator(); gla.sheet(); x += 1; break; default: x += 0; break; } } while (x < 1);

3rd Mar 2018, 3:49 PM
Nathan Lewis
Nathan Lewis - avatar
2 Antworten
+ 1
Why don't you add a Yes/No condition where the if the user may want to add a next input, then he can, else the do-while loop terminates.
3rd Mar 2018, 5:56 PM
Aaron Stone
Aaron Stone - avatar
0
I attempted it with the x+= 1. Just throws exceptions
3rd Mar 2018, 10:57 PM
Nathan Lewis
Nathan Lewis - avatar