Sum of bit differences for numbers from 0 to N | Set 2 | Java program to find the sum of bit differences between consecutive numbers from 0 to N using recursion ; Recursive function to find sum of different bits between consecutive numbers from 0 to N ; Base case ; Calculate the Nth term ; Driver Code ; Given number ; Function call
class GFG { static int totalCountDifference ( int n ) { if ( n == 1 ) return 1 ; return n + totalCountDifference ( n / 2 ) ; } public static void main ( String [ ] args ) { int N = 5 ; System . out . println ( totalCountDifference ( N ) ) ; } }