Interview Questions

How to find maximum of two numbers without using comparison operator in Java?

Use the following methods to find maximum of two numbers without using comparison operator in Java

public static int max(int a , int b)
        {
                return  (int) ((int)(a+b) + (Math.sqrt(Math.pow(a-b, 2))))/2;
        }
       
        public static int max1(int a,int b)
        {
                int d = a - b;
                int k = (d >> 1) & 0x1;
                int max = a - k * d;
                return max;
        }