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);
2 Réponses
+ 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.
0
I attempted it with the x+= 1. Just throws exceptions