Java Ternary operator explanation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Java Ternary operator explanation

Hi guys So I don’t get how to understand this code how can I know how to understand it properly Int= smallest (a<b)? (a<c?a:c) : (b<c?b:c); return smallest;

14th Jan 2023, 3:37 AM
Melissa 123
Melissa 123 - avatar
1 Answer
+ 5
ternary operator is a short of if else statement. int x = a > b ? a : b; if (a > b) x = a; else x = b; So here if (a < b) { if (a < c) smallest = a; else smallest = c; } else { if (b < c) smallest = b; else smallest = c; }
14th Jan 2023, 4:08 AM
A͢J
A͢J - avatar