Given a, b, c. How to find the minimum of them for two comparisons?
2 answers
Thanks for the help, but I got it more readable))
if (a < b){ min = a; }else{ min = b; } if (min > c){ min = c; } |
You can absolutely no comparisons:
private static int Min (int a, int b) { return (a + b - Math.abs(a - b)) / 2; } Min(Min(a, b), c); Math.abswork without comparisons? - Andrey NOP- @AndrewNOP in java source code - no , but in general it is possible without comparisons . - zRrr
- Well, then either take the library
Math.min()right away, or write your full version without using comparisons, otherwise what's the point? - Andrey NOP - This is a task for logic, and in the case of using such functions it does not count) - Bek Murat
|
d = ((a > b)? b : a); result = (d > c)? c : d;- Igor