Evil number
Write a program to check whether the given number is Evil Number or not in Java A number is said to be an Evil number if and only if the binary equivalent of the number is having an even number of 1’s. The entered number must be a whole number.
Write a program to check whether the given number is Evil Number or not in Java
A number is said to be an Evil number if and only if the binary equivalent of the number is having an even number of 1’s. The entered number must be a whole number.
import java.io.*;
public class Evil_no
{
int num;
String s="";
int r=0;
int n;
void input()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the number");
num=Integer.parseInt(br.readLine());
n=num;
}
boolean compute()
{
int count=0;
while(num!=0)
{
s=num%2+s; // add each binary digit on the left
num=num/2;
}
int l=s.length();
for(int i=0;i<l;i++)
{
if(s.charAt(i)=='1')
r++; // count the 1s in the binary form
}
if(r%2==0)
return true;
else
return false;
}
void display()
{
boolean evil=compute(); // builds s before it is printed
System.out.println("The number is:"+n);
System.out.println("Binary equivalent is:"+s);
if(evil)
System.out.println("Evil number");
else
System.out.println("Not evil number");
}
public static void main() throws IOException
{
Evil_no Obj=new Evil_no();
Obj.input();
Obj.display();
}
}Output:-
Enter the number
12
The number is 12
Binary equivalent is 1100
Evil number
Related Posts
Continue learning with these related articles

Logic Gates for ISC Class 11: Truth Tables, Universal Gates, Half and Full Adder
ISC Class 11 Computer Science notes on logic gates: AND, OR, NOT, NAND, NOR, XOR and XNOR with truth tables, why NAND and NOR are universal gates, and half adder and full adder circuits with their Boolean expressions.
Decimal to Binary Conversion in Java: 3 Programs with Examples
How to convert a decimal number to binary on paper and in Java: three programs (String, place value and Integer.toBinaryString), binary to decimal, a dry run and common mistakes.

ISC Class 11 Computer Science Sample Paper 2026-27 with Solutions
A full 70-mark ISC Class 11 Computer Science sample paper for the 2026-27 annual exam: MCQs, number systems, propositional logic, logic gates, Java classes, arrays, strings, searching and sorting, and computing ethics, with complete worked solutions.