All puzzles
Per page
F
String ยท Count substrings

Double letters

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;
F1
if (word.substring(i, i + 1).equals(word.substring(i + 1, i + 2))) {
F2
}
F3
}
F4
public static int countDoubles(String word) {
F5
count++;
F6
int count = 0;
F7
}
F8
for (int i = 0; i < word.length(); i++) {
F9
for (int i = 0; i < word.length() - 1; i++) {
F10

Answer key: F. Double letters

Order: 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.