Evil Number Program in Java


import java.util.Scanner;
public class EvilNumber {
    public static void main(String[] args)
    {
        int n,num;
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter number=");
        n = sc.nextInt();
        
        int binaryDigits=0;  
        String binary = "";
        num=n;
        while (num > 0) 
        {
            binary= num % 2 + binary ;
            if(num%2==1)
            {
                binaryDigits++;
            }
            num = num / 2;
        }
        if(binaryDigits%2==0)
        {
            System.out.println("Binary of "+n+"="+binary);
            System.out.println("Evil Number");
        }
        else
        {
            System.out.println("Binary of "+n+"="+binary);
            System.out.println("Not Evil Number");
        }
        
    }
}


Output:

Enter number=23
Binary of 23=10111
Evil Number
learn java study java