Computer Science, asked by shivanimahawarp83wef, 4 months ago

Q16. Rewrite the following code using ternary operator.
a) If (x >y)
System.out.println(x);
else
System.out.println(y);
b) If(discount>500)
System.out.println("Rs" +discount);
else
System.out.println("Rs" +discount +500);​

Answers

Answered by jatinshishodia123
2

Answer:

Full answer in explanation.

Explanation:

A) String ( or whatever type of variable x is )

Here I am assuming it is String.

String result_a = ( x > y ) ? x : y;

System.out.println(result_a);

B) Here I am assuming it is int.

int result_b = ( discount > 500 ) ? discount : discount + 500;

System.out.println("Rs " + result_b);

Similar questions