0

If i have lots of values and must use the switch statement,how can i write it?

the professor ask i to get user's input of their ages.if they enter wrong value,i need to require them to enter again. what's more ,he ask i to use the switch statement. my problem is that it is impossible for me to write lots of cases,so, does anyone have any idea how to write it?

20th Oct 2017, 4:57 PM
YuHai
YuHai - avatar
2 Answers
+ 4
There's the default statement, in this case you want to do cases for the ages, and the default case takes all other inputs, like: switch (i){ case 5: System.out.println(...); case 10: //code default: // some stuff
20th Oct 2017, 5:11 PM
Jonas Schröter
Jonas Schröter - avatar
+ 1
thank you,Jonas!
22nd Oct 2017, 6:18 AM
YuHai
YuHai - avatar