-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitwiseOperator.java
More file actions
34 lines (32 loc) · 865 Bytes
/
bitwiseOperator.java
File metadata and controls
34 lines (32 loc) · 865 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
import java.util.ArrayList;
import java.util.Scanner;
public class bitwiseOperator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = 0, b = 0, c = 0;
int n = sc.nextInt();
ArrayList<Integer> arr = new ArrayList<Integer>(100);
while (n > 0) {
int rem = n % 2;
arr.add(rem);
if (rem == 1) {
a++;
}
n = n / 2;
}
for (int i = 0; i < arr.size(); i++) {
if (arr.get(i) == 1) {
b = i;
break;
}
}
for (int i = arr.size() - 1; i >= 0; i--) {
if (arr.get(i) == 1) {
c = i;
break;
}
}
System.out.println(a + "#" + b + "#" + c);
sc.close();
}
}