Odious number | Java program to check if a number is Odious Number or not ; Function to get no of set bits in binary representation of passed binary no . Please refer below for details of this function : https : www . geeksforgeeks . org / count - set - bits - in - an - integer / ; Check if number is odious or not ; Driver Code
import java . io . * ; import java . math . * ; class GFG { static int countSetBits ( int n ) { int count = 0 ; while ( n != 0 ) { n &= ( n - 1 ) ; count ++ ; } return count ; } static boolean checkOdious ( int n ) { return ( countSetBits ( n ) % 2 == 1 ) ; } public static void main ( String args [ ] ) { int num = 32 ; if ( checkOdious ( num ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }