-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvil.java
More file actions
58 lines (54 loc) · 1.04 KB
/
Copy pathEvil.java
File metadata and controls
58 lines (54 loc) · 1.04 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.util.*;
public class Evil
{
int N,D=0,c=0;
String b="",b1="";
void input()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Number");
N=sc.nextInt();
if(N<=2||N>=100)
{
System.out.println("INVALID INPUT");
System.exit(0);
}
}
void binary()
{
int n=N;
while(n>0)
{
D=(D*10)+n%2;
b+=Integer.toString(n%2);
n=n/2;
}
for(int i=b.length()-1;i>=0;i--)
b1+=b.charAt(i);
D=Integer.parseInt(b1);
}
void count()
{
while(D>0)
{
if(D%10==1)
c++;
D/=10;
}
}
void display()
{
if(c%2==0)
System.out.println("EVIL NUMBER");
else
System.out.println("NOT AN EVIL NUMBER");
}
public static void main()
{
Evil ob=new Evil();
ob.input();
ob.binary();
ob.count();
ob.display();
}
}