-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathDay10:BinaryNumbers.java
More file actions
37 lines (35 loc) · 772 Bytes
/
Copy pathDay10:BinaryNumbers.java
File metadata and controls
37 lines (35 loc) · 772 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.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int c=1;
int max=0;
boolean prev=false;
while(n!=1){
if(n%2==1){
if(prev)
c++;
else{
c=1;
prev=true;
}
}
else{
if(c>max)
max=c;
prev=false;
}
n/=2;
}
if(prev)
c++;
if(c>max)
max=c;
System.out.println(max);
}
}