print
Advertisment
Advertisment

Evil Odious Number in java

Example

  import java.util.Scanner;
    class EvilNumber{
     public static void main(String[] args) {
  
    int num;
    int count = 0; 
    Scanner sc = new Scanner(System.in);

    System.out.println("enter a number");

    num = sc.nextInt();

    /* count the no. of 1s in the binary represent 
       of the number*/

    while(num!=0)
    {
      if(num%2==1)
      {
        count++;
      }
      num/=2;

    }
    /* If the number of 1s is even then Evil else Odious */
    if(count%2 == 0) //check even
    {
      System.out.println("Evil Number");
    }
    else
    {
          System.out.println("Odious Number");
      }
   }
 }
 

Output :

 
   
  enter a number
  12
  it is Evil number
   
Advertisment
Advertisment
arrow_upward