XOR of Sum of every possible pair of an array | Java program to find XOR of sum of every possible pairs in an array ; Function to find XOR of sum of all pairs ; Calculate xor of all the elements ; Return twice of xor value ; Drivers code
import java . io . * ; class GFG { static int findXor ( int arr [ ] , int n ) { int xoR = 0 ; for ( int i = 0 ; i < n ; i ++ ) { xoR = xoR ^ arr [ i ] ; } return xoR * 2 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 5 , 6 } ; int n = arr . length ; System . out . println ( findXor ( arr , n ) ) ; } }