0% found this document useful (0 votes)
9 views1 page

Count Repeated Characters in String

This code checks how many times a substring repeats in a string that is repeated a given number of times. It takes a string, repeat count, and substring to check for as inputs, repeats the string and counts the occurrences of the substring, returning the count.

Uploaded by

sushant sharma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Count Repeated Characters in String

This code checks how many times a substring repeats in a string that is repeated a given number of times. It takes a string, repeat count, and substring to check for as inputs, repeats the string and counts the occurrences of the substring, returning the count.

Uploaded by

sushant sharma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

public class RepeatedSubString {

public static void main(String[] args) {

String str = "aba";

int repeatCount = 10;

String checkFor = "a";

long result = checkRepeatedCharCount(str, repeatCount, checkFor);

[Link](result);

private static Long checkRepeatedCharCount(String str, int repeatCount, String checkFor) {

int strLength = [Link]();

StringBuilder sb = new StringBuilder(str);


int counter = 0;

for (int i = 0; i < repeatCount - strLength; i++) {

if (counter < strLength) {


[Link]([Link](counter));
counter++;
}

if (counter > strLength - 1) {


counter = 0;
}

List<Character> list = new ArrayList<>();

for (char ch : [Link]().toCharArray()) {

[Link](ch);
}

[Link]([Link]());
Map<Object, Long> optional = [Link]().sorted().filter(n -> [Link]('a'))
.collect([Link](n -> n, [Link]()));

[Link](optional);
long val = 0;
for ([Link]<Object, Long> entry : [Link]()) {
// Object key = [Link]();
val = [Link]();
return val;
}

return val;

You might also like