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;
num=num/2;
}
int l=s.length();
for(int i=0;i<l;i++)
{
r+=s.charAt(i);
}
if(r%2==0)
return true;
else
return false;
}
void display()
{
System.out.println("The number is:"+n);
System.out.println("Binary equivalent is:"+s);
if(compute()==true)
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

ISC Practical 2027: College Enrolment Code Validator and Stream Report – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 question: validate college enrolment codes made of a stream, year and serial number, give the exact reason for each rejection, auto-correct lowercase streams and prepare a stream-wise report.

ISC Practical 2027: Digital Lock Security Code Analyzer – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 number-logic question: for a 5 to 10 digit security code, find the first and last digits, odd and even position sums, product of non-zero digits, digit frequency and classify the code as STRONG, MODERATE or WEAK.

Boolean Algebra for ISC Class 12: Laws, Canonical SOP and POS, and Simplification
ISC Class 12 Computer Science notes on Boolean algebra: all the laws and theorems, duality, De Morgan's laws, minterms and maxterms, converting to canonical SOP and POS, and step-by-step algebraic simplification with solved examples.