Count of N | Java program for the above approach ; Function to find count of N - digit numbers with single digit XOR ; Range of numbers ; Calculate XOR of digits ; If XOR <= 9 , then increment count ; Print the count ; Driver Code ; Given Number ; Function Call
class GFG { public static void countNums ( int N ) { int l = ( int ) Math . pow ( 10 , N - 1 ) , r = ( int ) Math . pow ( 10 , N ) - 1 ; int count = 0 ; for ( int i = l ; i <= r ; i ++ ) { int xor = 0 , temp = i ; while ( temp > 0 ) { xor = xor ^ ( temp % 10 ) ; temp /= 10 ; } if ( xor <= 9 ) count ++ ; } System . out . println ( count ) ; } public static void main ( String [ ] args ) { int N = 2 ; countNums ( N ) ; } }