Count odd and even Binomial Coefficients of N | Java program for the above approach ; Function to count set bits in binary representation of number N ; Count set bits in N ; Return the final count ; Driver code ; Print odd Binomial coefficients ; Print even Binomial coefficients
import java . util . * ; class GFG { static int countSetBits ( int N ) { int count = 0 ; while ( N != 0 ) { N = N & ( N - 1 ) ; count ++ ; } return count ; } public static void main ( String [ ] args ) { int N = 4 ; int bits = countSetBits ( N ) ; System . out . println ( " Odd ▁ " + " : ▁ " + ( int ) ( Math . pow ( 2 , bits ) ) ) ; System . out . println ( " Even ▁ " + " : ▁ " + ( N + 1 - ( int ) ( Math . pow ( 2 , bits ) ) ) ) ; } }