-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsecutive_Sequence_of_0.java
More file actions
50 lines (44 loc) · 1.09 KB
/
Consecutive_Sequence_of_0.java
File metadata and controls
50 lines (44 loc) · 1.09 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
//Finding the consecutive sequence of 0 in the number when the number is repeated for K times.
//Like if number is 1001 and K is 3 then number will be 100110011001
package placements;
import java.util.*;
public class Zero {
static int count(String s )
{
int counter =0;
int cc[]= new int[s.length()];
int k=0;
for(int i =0;i<s.length();i++)
{
if (s.charAt(i)=='0')
counter++;
else if(i<s.length()&&s.charAt(i)!='0')
{
cc[k++]=counter;
counter=0;
}
else
{
cc[k++]=counter;
counter =0;
}
}
Arrays.sort(cc);
return cc[cc.length-1];
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value of K");
int k =sc.nextInt();
System.out.println("Enter the Number");
Long x =sc.nextLong();
String a = x.toString();
String n = "";
for(int i =1;i<=k;i++)
{
n=n.concat(a);
}
System.out.println(n);
System.out.println(count(n));
}
}