-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHacker_rank.java
More file actions
36 lines (35 loc) · 869 Bytes
/
Hacker_rank.java
File metadata and controls
36 lines (35 loc) · 869 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
package practicetime;
import java.util.*;
public class Hacker_rank
{
public static void main(String[] args) {
int r;String s =" ";
int count=0,min=0;
Scanner in = new Scanner(System.in);
System.out.println(" Enter the Number ");
int n = in.nextInt();
while(n>0)
{
r=n%2;
s=r+s;
n=n/2;
}
System.out.println(s);
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='1')
{
count++;
}
else
{
if(count>min)
{
min=count;
}
count=0;
} }
System.out.println("Maximum Occurence of Consecutive 1 is - "+min);
in.close();
}
}