Computer Science, asked by Enegizer, 6 months ago

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 imtiyazallam
1

Answer:

System.out.println((a > b) ? a : (a < b) ? b : "Both are equal");

Answered by anindyaadhikari13
1

\star\:\:\:\sf\large\underline\blue{Question:-}

  • Write the given code using ternary operator.

\star\:\:\:\sf\large\underline\blue{Answer:-}

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