int a = 63, b = 36; boolean x = (a > b)? true : false; int y = (a < b)? a : b;
Let’s analyze the given statements step by step:
Boolean Expression for x:
boolean x = (a > b) ? true : false;
Here, the ternary operator (condition) ? true : false evaluates the condition a > b and assigns true if the condition is true; otherwise, it assigns false.
a > ba = 63 and b = 3663 > 36 is true.Thus, x will be assigned true.
Integer Expression for y:
int y = (a < b) ? a : b;
Similarly, the ternary operator (condition) ? a : b evaluates the condition a < b and assigns a if the condition is true; otherwise, it assigns b.
a < ba = 63 and b = 3663 < 36 is false.Thus, y will be assigned b, which is 36.
Summary:
x is true.y is 36.First read the answer fully, then try to explain it in your own words. After that, open a few related questions and compare the concepts. This method helps you remember the topic for a longer time and improves exam preparation.