-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvilNumber.java
More file actions
26 lines (24 loc) · 781 Bytes
/
Copy pathEvilNumber.java
File metadata and controls
26 lines (24 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package basic;
import java.util.Scanner;
class EvilNumber {
public static void main(String[] args) {
Scanner ob = new Scanner(System.in);
System.out.print("INPUT\t:");
int n = ob.nextInt();
String binary = Integer.toBinaryString(n); //Storing binary equivalent of entered no.
System.out.println("BINARY EQUIVALENT :" + binary);
int len = binary.length();
int c = 0;
for (int i = 0; i < len; i++) {
if (binary.charAt(i) == '1') {
c++;
}
}
System.out.println("NO. OF 1's :" + c);
if (c % 2 == 0) {
System.out.println("OUTPUT :EVIL NUMBER");
} else {
System.out.println("OUTPUT :NOT AN EVIL NUMBER");
}
}
}