Calculate the number of set bits for every number from 0 to N | Java implementation of the approach ; Function to find the count of set bits in all the integers from 0 to n ; Driver code
class GFG { static void findSetBits ( int n ) { for ( int i = 0 ; i <= n ; i ++ ) System . out . print ( Integer . bitCount ( i ) + " ▁ " ) ; } public static void main ( String [ ] args ) { int n = 5 ; findSetBits ( n ) ; } }