Find all possible pairs with given Bitwise OR and Bitwise XOR values | Java code for the above approach ; Function to find pairs with XOR equal to A and OR equal to B ; Iterate from 1 to B ; Check if ( i OR y ) is B ; Driver Code
import java . util . * ; class GFG { static void findPairs ( int A , int B ) { for ( int i = 1 ; i <= B ; i ++ ) { int y = A ^ i ; if ( y > 0 && ( i y ) == B ) { System . out . println ( i + " ▁ " + y ) ; } } } public static void main ( String [ ] args ) { int A = 8 , B = 10 ; findPairs ( A , B ) ; } }