I have been trying to write a substring search method that gets the count of the number of patterns that show up in a string. My question has to deal with the logic of the multiple for loops that I have and the if statements. If the input string is AABABAA and the input pattern is AA it should iterate through and return count of 2. Any suggestions to help me finish my code?
public int getCount(String pattern){
for (int i=0; i< this.strand.length()-pattern.length(); i++){
for (int k=0; k<pattern.length(); k++){
if (this.strand.charAt(i) == pattern.charAt(k)){
for(int j=1; j<pattern.length()-1; j++){
if (this.strand.charAt(j+i) == pattern.charAt(j)){
if(j==pattern.length()){
Count++;
}
}
else{
break;
}
}
}
else if (this.strand.charAt(i)!=pattern.charAt(k)){
break;
}
}
}
return Count;
}