+ 8

How do you read this condition involving ternary operators?

a>b?a>c?a:c:b>c?b:c

15th Jul 2018, 9:24 AM
silentlearner
silentlearner - avatar
7 Respostas
+ 7
if a>b if a>c return a else return c else if b>c return b else return c Hope this is more comprehensible : )
15th Jul 2018, 9:37 AM
Ipang
+ 7
Ipang Thank you! Your explanation helped.
15th Jul 2018, 9:40 AM
silentlearner
silentlearner - avatar
+ 3
You're welcome silentlearner, glad it helps : )
15th Jul 2018, 9:41 AM
Ipang
+ 2
I would read it from left to right, looking at the colons to see where the next statement ends. a>b?(a>c?a:c):(b>c?b:c); But in real code rather use if/else like Ipang posted. Otherwise it is too confusing to read and understand for others, as you noticed.
15th Jul 2018, 9:42 AM
Matthias
Matthias - avatar
+ 1
int X=2, int y=5; result =x_ _? system.out.println();
23rd Jul 2018, 4:30 AM
Ratnakar
Ratnakar - avatar
+ 1
Ratnakar rockzz please move your question into your own thread, posting a different question being irrelevant with original question here is not nice, Thanks for understanding : )
23rd Jul 2018, 5:13 AM
Ipang
0
int X=2, int y=5; int result =x_ _; system.out.println(); plz tell me the fill in the blanks
23rd Jul 2018, 4:34 AM
Ratnakar
Ratnakar - avatar