Choose X such that ( A xor X ) + ( B xor X ) is minimized | Java implementation of above approach ; finding X ; finding Sum ; Driver Code
import java . io . * ; class GFG { public static int findX ( int A , int B ) { return A & B ; } public static int findSum ( int A , int B ) { return A ^ B ; } public static void main ( String [ ] args ) { int A = 2 , B = 3 ; System . out . print ( " X ▁ = ▁ " + findX ( A , B ) + " , ▁ Sum ▁ = ▁ " + findSum ( A , B ) ) ; } }