Friday, April 3, 2015

Find Max from two numbers without using if-else or comparison


/**
* Formula : Max = [(A+B)/2 ]   + [ |A -B| /2 ]
*
*/

private static int max(int i, int j) {
       int a = (i+j)/2;
       int b = Math.abs((i-j)/2);
       return a+b;

}

No comments:

Post a Comment