J'essaye de faire un programme qui trouve la plus grande occurrence continue dans une chaîne. Voici mon code.trouver la plus haute occurrence continue d'un caractère dans une chaîne jette l'index de chaîne hors des limites
public class Assign2{
public int maxOcc(String str){
System.out.println("Entered method");
int j,i,counter;
j = i = 0;
int max = 0;
int size = str.length();
System.out.println("Size of string-->"+size);
for(i = 0;i<size;i++){
j = i;
counter = 0;
while(str.charAt(i)==str.charAt(j) && j < size){
counter++;
j++;
}
if(counter > max)
max = counter;
}
return max;
}
public static void main(String args[]){
Assign2 a = new Assign2();
System.out.println(a.maxOcc("abbbbaaaaaagsgsgaaaa"));
}
}
Cependant, lorsque je tente d'exécuter ce programme, je gen un « indice de chaîne hors limites » idées .Tout?
Oh merci beaucoup !!!!!!! –