Find XOR sum of Bitwise AND of all pairs from given two Arrays | Java algorithm for the above approach ; Function to calculate the XOR sum of all ANDS of all pairs on A [ ] and B [ ] ; Variable to store xor sums of first array and second array respectively . ; Xor sum of first array ; Xor sum of second array ; Required answer ; Driver code ; Input ; Function call
import java . io . * ; class GFG { static int XorSum ( int A [ ] , int B [ ] , int N , int M ) { int ans1 = 0 , ans2 = 0 ; for ( int i = 0 ; i < N ; i ++ ) ans1 = ans1 ^ A [ i ] ; for ( int i = 0 ; i < M ; i ++ ) ans2 = ans2 ^ B [ i ] ; return ( ans1 & ans2 ) ; } public static void main ( String [ ] args ) { int A [ ] = { 3 , 5 } ; int B [ ] = { 2 , 3 } ; int N = A . length ; int M = B . length ; System . out . print ( XorSum ( A , B , N , M ) ) ; } }