Write a Program in Java to input a number and check whether it is an Evil Number or not. An Evil number is a positive whole number which has even number of 1’s in its binary equivalent.
Answers
Answered by
3
Ok so first let me tell you what's an Evil number is U can skip this if you know what is an Evil number.
Evil Number : An Evil number is a positive whole number which has even number of 1’s in its binary equivalent.
And now I'll give you an example to your question.....
Example: Binary equivalent of 9 is 1001, which contains even number of 1’s.
A few evil numbers are 3, 5, 6, 9….
Design a program to accept a positive whole number and find the binary equivalent of the number and count the number of 1’s in it and display whether it is a Evil number or not with an appropriate message. Output the result in format given below:
Example 1
INPUT : 15
BINARY EQUIVALENT : 1111
NO. OF 1’s : 4
OUTPUT : EVIL NUMBER
Example 2
INPUT : 26
BINARY EQUIVALENT : 11010
NO. OF 1’s : 3
OUTPUT : NOT AN EVIL NUMBER
HAPPY PROGRAMMING !
(No one is happy doing programming XD :p)
Evil Number : An Evil number is a positive whole number which has even number of 1’s in its binary equivalent.
And now I'll give you an example to your question.....
Example: Binary equivalent of 9 is 1001, which contains even number of 1’s.
A few evil numbers are 3, 5, 6, 9….
Design a program to accept a positive whole number and find the binary equivalent of the number and count the number of 1’s in it and display whether it is a Evil number or not with an appropriate message. Output the result in format given below:
Example 1
INPUT : 15
BINARY EQUIVALENT : 1111
NO. OF 1’s : 4
OUTPUT : EVIL NUMBER
Example 2
INPUT : 26
BINARY EQUIVALENT : 11010
NO. OF 1’s : 3
OUTPUT : NOT AN EVIL NUMBER
HAPPY PROGRAMMING !
(No one is happy doing programming XD :p)
Anjula:
Nice !
Answered by
2
❇
✔
❇ - An Evil number is a positive whole number which has even number of 1’s in its binary equivalent.
❇ - Binary equivalent of 9 is 1001 which contains even number of 1’s.
A few evil numbers are 3, 5, 6, 9….
Example 1
INPUT : 15
BINARY EQUIVALENT : 1111
NO. OF 1’s : 4
OUTPUT : EVIL NUMBER
Example 2
INPUT : 26
BINARY EQUIVALENT : 11010
NO. OF 1’s : 3
OUTPUT : NOT AN EVIL NUMBER
Similar questions