I have a method that I want to return some path of a string example if I input : xxdrrryy - it should return rrr, I can only return a string of length 3, so I am trying this , but I'm stalked . it must be the occurrence of a letter three times consecutively
public String countTriple(String str) {
int count = 1;
char currChar = str.charAt(0);
for(int i=1; i<str.length(); i++) {
if(currChar == str.charAt(i)) {
count++;
if(count == 3) {
StringBuilder sb = new StringBuilder("");
for(int j=0; j<3;j++) {
sb.append(currChar);
}
return sb.toString();
}
}
else {
count = 1;
}
currChar = str.charAt(i);
}
return null; //no triple found
}
aaabcccdeeedid you want justaaaor allaaa, ccc, eee?