+ 2

Can we use a conditional operator in 'switch' statement??

eg. switch(a==b)

13th Dec 2019, 11:41 AM
Charu Jain
Charu Jain - avatar
5 odpowiedzi
+ 7
In Java, switch does not support boolean type(a==b will return a boolean value). It can work with integer or character value(so you can do something like 1 for true, 0 for false OR 't' for true & 'f' for false using if statement, and then use it in switch statement).[it does not make much sence to do all this when it can be done using simple if else statement]
13th Dec 2019, 12:55 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 3
No. You can simply use 'if' instead.
13th Dec 2019, 11:52 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 1
Okkk thanks
13th Dec 2019, 12:06 PM
Charu Jain
Charu Jain - avatar
+ 1
No
15th Dec 2019, 3:40 AM
Samavedam Praneeth
Samavedam Praneeth - avatar