Generate an array of minimum sum whose XOR of same | Java implementation of the above approach ; Function to generate an array whose XOR with same - indexed elements of the given array is always a prime ; Traverse the array ; If current array element is 2 ; Print its XOR with 3 ; Otherwise ; Print its XOR with 2 ; Driver code ; Given array ; Size of the array ; Prints the required array
class GFG { private static void minXOR ( int Arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { if ( Arr [ i ] == 2 ) { System . out . print ( ( Arr [ i ] ^ 3 ) + " ▁ " ) ; } else { System . out . print ( ( Arr [ i ] ^ 2 ) + " ▁ " ) ; } } } public static void main ( String [ ] args ) { int Arr [ ] = { 5 , 4 , 7 , 6 } ; int N = Arr . length ; minXOR ( Arr , N ) ; } }