Quantcast
Channel: Can you use conditional statements in switch-case in Android? - Stack Overflow
Browsing all 8 articles
Browse latest View live

Answer 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



Answer 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 Article

Answer 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 Article

Answer 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 Article

Answer 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 Article


Answer 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 Article

Answer 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 Article

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 Article

Browsing all 8 articles
Browse latest View live




Latest Images