if(a>b) system.out.println(a) else if(b>a) System.out.println(b) else System.out.println("both are equal).Convert it into ternary operator.
Answers
Answered by
1
Answer:
System.out.println((a > b) ? a : (a < b) ? b : "Both are equal");
Answered by
1
- Write the given code using ternary operator.
Given code segment,
if(a>b)
System.out.println(a);
else if(b>a)
System.out.println(b);
else
System.out.println("both are equal);
The above code can be written using ternary Operator as,
System.out.println((a>b)?a:(b>a)?b:"Both are equal.");
Similar questions