Compute the minimum or maximum of two integers without branching | JAVA implementation of above approach ; Function to find minimum of x and y ; Function to find maximum of x and y ; Driver code
class GFG { static int CHAR_BIT = 4 ; static int INT_BIT = 8 ; static int min ( int x , int y ) { return y + ( ( x - y ) & ( ( x - y ) >> ( INT_BIT * CHAR_BIT - 1 ) ) ) ; } static int max ( int x , int y ) { return x - ( ( x - y ) & ( ( x - y ) >> ( INT_BIT * CHAR_BIT - 1 ) ) ) ; } public static void main ( String [ ] args ) { int x = 15 ; int y = 6 ; System . out . println ( " Minimum ▁ of ▁ " + x + " ▁ and ▁ " + y + " ▁ is ▁ " + min ( x , y ) ) ; System . out . println ( " Maximum ▁ of ▁ " + x + " ▁ and ▁ " + y + " ▁ is ▁ " + max ( x , y ) ) ; } }