Make a condition with restrictions Java

Have a task on my education in Java: Make a condition, which is true if only one of X and Z values is less than 20. The way how to do that is like:

(X < 20 && Y >= 20) || (X >= 20 && Y < 20)

Or

(a < 20) != (b < 20)

But I have restrictions, it should be solved using no more than 2 comparison operators, no * / + – operators, no bitwise operators

Answer

 return Math.max(a, b) >= 20 && Math.min(a, b) < 20;

Leave a Reply

Your email address will not be published. Required fields are marked *