Can you use conditional statements in switch-case in Android?
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 an int value:switch...
View ArticleAnswer by brso05 for Can you use conditional statements in switch-case in...
You can't do this use if then statement.if(age > 79){ //do stuff}else if(age > 50){ //do stuff}else{ /do stuff}etc...
View ArticleAnswer by Elliott Frisch for Can you use conditional statements in...
No. You cannot do this,switch (age){case (>79): // Do this stuff break;case (>50): // Do this other stuff break;}You need an if and else,if (age > 79) { // do this stuff.} else if (age >...
View ArticleAnswer by shinjw for Can you use conditional statements in switch-case in...
If you are using a loop you might want to look at What is the "continue" keyword and how does it work in Java?. This is not a good place to use switch.if(age > 79){ //do stuff continue; // STOP FLOW...
View ArticleAnswer by NavinRaj Pandey for Can you use conditional statements in...
each case of switch is supposed to be an integer or String since JavaSE 7 and you are trying to feed a boolean value to it so its not possible .Read oracle doc to know about java switch in...
View ArticleAnswer by drage0 for Can you use conditional statements in switch-case in...
You can't use conditional statements with switch.But you CAN do it with if statements! If you have a loop you can use continue to stop any upcoming lines and start from the beginning of the innermost...
View ArticleAnswer by Williem for Can you use conditional statements in switch-case in...
It is not possible. Instead, Try this minimalist approach age > 79 ? first_case_method() : age > 50 ? second_case_method() : age > 40 ? third_case_method() : age > 30 ? fourth_case_method()...
View ArticleAnswer by Vikram for Can you use conditional statements in switch-case in...
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...
View Article