-
Notifications
You must be signed in to change notification settings - Fork 0
/
Number80.java
79 lines (78 loc) · 1.58 KB
/
Number80.java
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import java.util.*;
public class Number80 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n,m,c=0,c1=0,c2=0,c3=0,d;
String p,q;
System.out.println("Enter two numbers");
n=sc.nextInt();
m=sc.nextInt();
p=Integer.toBinaryString(n);
q=Integer.toBinaryString(m);
if(p.length()!=q.length())
{
if(p.length()>q.length())
{
for(int i=1;i<=p.length()-q.length();i++)
{
q="0"+q;
}
for(int i=0;i<q.length();i++)
{
if(p.charAt(i)=='1')
c++;
else
c1++;
if(q.charAt(i)=='1')
c2++;
else
c3++;
}
if(c==c2&&c1==c3)
System.out.println("True");
else
System.out.println("False");
}
else if(p.length()<q.length())
{
for(int i=1;i<=q.length()-p.length();i++)
{
p="0"+p;
}
for(int i=0;i<p.length();i++)
{
if(p.charAt(i)=='1')
c++;
else
c1++;
if(q.charAt(i)=='1')
c2++;
else
c3++;
}
if(c==c2&&c1==c3)
System.out.println("True");
else
System.out.println("False");
}
}
else
{
for(int i=0;i<q.length();i++)
{
if(p.charAt(i)=='1')
c++;
else
c1++;
if(q.charAt(i)=='1')
c2++;
else
c3++;
}
if(c==c2&&c1==c3)
System.out.println("True");
else
System.out.println("False");
}
}
}