Count the places in word where the same letter appears twice in a row.
countDoubles("balloon") returns 2.
10 strips: F1 to F10
return count; F1if (word.substring(i, i + 1).equals(word.substring(i + 1, i + 2))) { F2} F3} F4public static int countDoubles(String word) { F5count++; F6int count = 0; F7} F8for (int i = 0; i < word.length(); i++) { F9for (int i = 0; i < word.length() - 1; i++) { F10Order: F5, F7, F10, F2, F6, F8, F3, F1, F4. Extra: F9
public static int countDoubles(String word) {
int count = 0;
for (int i = 0; i < word.length() - 1; i++) {
if (word.substring(i, i + 1).equals(word.substring(i + 1, i + 2))) {
count++;
}
}
return count;
} Extra strip: for (int i = 0; i < word.length(); i++) {. On the last letter, i + 2 is past the end of the String, so substring crashes.