-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvil_Number.java
More file actions
36 lines (36 loc) · 887 Bytes
/
Copy pathEvil_Number.java
File metadata and controls
36 lines (36 loc) · 887 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
27
28
29
30
31
32
33
34
35
36
import java.util.*;
class Evil_Number
{
static int convBinary(int n)
{
int bin=0;
while(n>0)
{
bin=bin*10+(n%2);
n=n/2;
}
return bin;
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("INPUT A NUMBER : ");
int n=sc.nextInt();
int binary = convBinary(n);
int c=0,d,copy=binary;
while(binary>0)
{
if((binary%10)==1)
c++;
binary=binary/10;
}
System.out.println("INPUT : "+n);
System.out.println("BINARY EQUIVALENT : "+copy);
System.out.println("NUMBER OF 1's : "+c);
System.out.print("OUTPUT : ");
if(c%2==0)
System.out.println("EVIL NUMBER");
else
System.out.println("NOT EVIL NUMBER");
}
}