In this line, I want to find out the initial index of the largest substring, all from the same character, and also calculate how many times this substring occurs in the main line.
ex: "aaakkkkbbkkkkk" In this case, the substring counter "kkkkk" is 5, and the starting position is 9.
My code is:
String str = "aaakkkkbbkkkkk"; int count = 0; //converting string into character array char[] vals = str.toCharArray(); for(int i=0; i < vals.length; ){ for(int j=i+1; j<vals.length; j++){ //if value match then increment counter if(vals[i]== str.charAt(j)){ counter++; } //else break from inner loop break; //break from inner loop } //assign the index value of j to the i to start with new substring i = vals.indexOf(j); }
My problems: it is impossible to save the counter value, because this counter value is the actual occurrence of the substring, and later I will compare the substring with the oncoming meeting.
I also do not adhere to this labeling with my logic.
source share