-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
24 lines (22 loc) · 778 Bytes
/
Solution.java
File metadata and controls
24 lines (22 loc) · 778 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
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String binary = Integer.toBinaryString(n);
int consecutive = 0;
int current = 0;
for (int i = 0; i < binary.length(); i++) {
if (Integer.parseInt(Character.toString(binary.charAt(i))) == 1) {
current++;
if (current > consecutive) {
consecutive = current;
}
} else {
current = 0;
}
}
System.out.println(consecutive);
}
}