Number of solutions of n = x + n âŠ • x | Java implementation of above approach ; Function to find the number of solutions of n = n xor x ; Counter to store the number of solutions found ; Driver code
import java . util . * ; import java . lang . * ; class GFG { static int numberOfSolutions ( int n ) { int c = 0 ; for ( int x = 0 ; x <= n ; ++ x ) if ( n == x + ( n ^ x ) ) ++ c ; return c ; } public static void main ( String args [ ] ) { int n = 3 ; System . out . print ( numberOfSolutions ( n ) ) ; } }