Count of even set bits between XOR of two arrays | Java program for the above approach ; Function that count the XOR of B [ ] with all the element in A [ ] having even set bit ; Count the set bits in A [ i ] ; check for even or Odd ; To store the count of element for B [ ] such that XOR with all the element in A [ ] having even set bit ; Count set bit for B [ i ] ; check for Even or Odd ; Driver Code
import java . util . * ; class GFG { static void countEvenBit ( int A [ ] , int B [ ] , int n , int m ) { int i , j , cntOdd = 0 , cntEven = 0 ; for ( i = 0 ; i < n ; i ++ ) { int x = Integer . bitCount ( A [ i ] ) ; if ( x % 2 == 1 ) { cntEven ++ ; } else { cntOdd ++ ; } } int [ ] CountB = new int [ m ] ; for ( i = 0 ; i < m ; i ++ ) { int x = Integer . bitCount ( B [ i ] ) ; if ( x % 2 == 1 ) { CountB [ i ] = cntEven ; } else { CountB [ i ] = cntOdd ; } } for ( i = 0 ; i < m ; i ++ ) { System . out . print ( CountB [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int A [ ] = { 4 , 2 , 15 , 9 , 8 , 8 } ; int B [ ] = { 3 , 4 , 22 } ; countEvenBit ( A , B , 6 , 3 ) ; } }