Count pairs with Bitwise XOR greater than both the elements of the pair | Java program for the above approach ; Function that counts the pairs whose Bitwise XOR is greater than both the elements of pair ; Stores the count of pairs ; Generate all possible pairs ; Find the Bitwise XOR ; Find the maximum of two ; If xo < mx , increment count ; Print the value of count ; Driver Code ; Function Call
import java . io . * ; import java . util . * ; class GFG { static void countPairs ( int [ ] A , int N ) { int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { int xo = ( A [ i ] ^ A [ j ] ) ; int mx = Math . max ( A [ i ] , A [ j ] ) ; if ( xo > mx ) { count ++ ; } } } System . out . println ( count ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 4 , 3 } ; int N = arr . length ; countPairs ( arr , N ) ; } }