Find array whose elements are XOR of adjacent elements in given array | Java implementation of the above approach ; Function to reconstruct the array arr [ ] with xor of adjacent elements ; Iterate through each element ; Store the xor of current and next element in arr [ i ] ; Function to print the array ; Driver Code ; Inputs ; Length of the array given ; Function call to reconstruct the arr [ ] ; Function call to print arr [ ]
import java . io . * ; class GFG { static int [ ] game_with_number ( int arr [ ] , int n ) { for ( int i = 0 ; i < n - 1 ; i ++ ) { arr [ i ] = arr [ i ] ^ arr [ i + 1 ] ; } return arr ; } static void print ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 11 , 1 , 2 , 3 } ; int n = arr . length ; int [ ] new_arr = game_with_number ( arr , n ) ; print ( new_arr , n ) ; } }