I can\'t seem to find a straight forward yes or no to this in my searching. In Android, is there a way to use a conditional statement in case-switch? For example, with age being
It can be done. The code needs to be slightly altered.
public static void main(String[]arguments)
{
int x=1, age=55;
switch(x)
{
case 1: if((age>=60)&&(age<200))
System.out.println("Senior Citizen");
case 2: if((age>=18)&&(age<60))
System.out.println("Adult");
case 3: if((age>=12)&&(age<18))
System.out.println("Teenager");
break;
default :
System.out.println("Child");
break;
}
}