I have a StringBuffer named "sentence." I need to replace all occurrences of "A", except occurrences of "A" at the end of a word, with "E".
Example: ABABA ---> EBEBA
However, my code returns EBEBE.
while (sentence.indexOf("A") >= 0 && sentence.indexOf("A") != sentence.indexOf("A ") && sentence.indexOf("A") != sentence.indexOf("A.")) { int AStart = sentence.indexOf("A"); int AEnd = AStart + "A".length(); sentence.replace(AStart, AEnd, "E"); }