How to use ternary operator to find greatest no of 3 numbers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to use ternary operator to find greatest no of 3 numbers

6th Mar 2017, 2:46 PM
Kishan Mittal
3 Answers
+ 1
int a=5,b=1,c=3; int max=a; int max2=b>max ? b:max; System.out.println(c>max2?c:max2 );
6th Mar 2017, 2:55 PM
Meharban Singh
Meharban Singh - avatar
0
int x = 2; int y = 4; int z = 3; int max = x > y? (x > z?x:z):(z>y?z:y); should work...
6th Mar 2017, 2:52 PM
Michael Szczepanski
Michael Szczepanski - avatar
0
thanks
7th Mar 2017, 3:47 PM
Kishan Mittal