-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuber.java
More file actions
37 lines (33 loc) · 789 Bytes
/
uber.java
File metadata and controls
37 lines (33 loc) · 789 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
37
import java.util.Arrays;
public class uber {
static boolean isPowerOfTwo(int n)
{
if (n == 0)
return false;
while (n != 1)
{
if (n % 2 != 0)
return false;
n = n / 2;
}
return true;
}
static int pair(int a[]) {
int c=0;
Arrays.sort(a);
int sum=0;
for (int i = 0; i < a.length-1; i++) {
for (int j = 1; j < a.length; j++) {
sum = a[i] + a[j];
if(isPowerOfTwo(sum))
c++;
}
}
return c;
}
public static void main(String[] args) {
int a[] = {1, -1, 2, 3};
int n = uber.pair(a);
System.out.println(n);
}
}