forked from srinathr91/TestJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
30 lines (21 loc) · 611 Bytes
/
Solution.java
File metadata and controls
30 lines (21 loc) · 611 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
import java.util.Scanner;
public class Solution {
static int getIntegerComplement(int n) {
String s=Integer.toBinaryString(n);
int lm=0;
for(int i=0;i<s.length();i++){
if(s.charAt(i)=='0'){
lm= (int) (lm+Math.pow(2,s.length()-1-i ));
}
}
return lm;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int res;
int _n;
_n = Integer.parseInt(in.nextLine());
res = getIntegerComplement(_n);
System.out.println(res);
}
}