Wrong answer fed in the system for a Question

Wrong answer in JAVA Course Q

The Q link is Multiple choice question in Java
I believe only 2 options are correct rather then 3
Please look into this, Thank you

@shreshtha63 All three options are actually correct, and here’s why:

The question requires returning x if x is greater than y; otherwise, return y. The key point is that if both values are equal, it doesn’t matter which one is returned since x == y.

  • Option 1: x < y ? y : x — This returns y if y is greater; otherwise, it returns x. When x > y, it returns x. When x < y, it returns y. If both are equal, it returns x, which is acceptable.
  • Option 3: x >= y ? x : y — This directly returns x when x is greater or equal to y; otherwise, it returns y. Again, this satisfies the condition.
  • Option 4: x <= y ? y : x — This returns y if x is less than or equal to y; otherwise, it returns x. It correctly handles all scenarios as well.

In all cases, the logic ensures the greater value is returned, and in the case of equality, either x or y is acceptable.