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?
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
+ 1
thank you,Jonas!