All puzzles
Per page
H
indexOf ยท Find, cut, repeat

Remove the dashes

Return phone with every dash removed.

removeDashes("555-867-5309") returns "5558675309".

10 strips: H1 to H10

int dash = copy.indexOf("-");
H1
copy = copy.substring(0, dash) + copy.substring(dash);
H2
}
H3
dash = copy.indexOf("-");
H4
}
H5
public static String removeDashes(String phone) {
H6
return copy;
H7
copy = copy.substring(0, dash) + copy.substring(dash + 1);
H8
String copy = phone;
H9
while (dash != -1) {
H10

Answer key: H. Remove the dashes

Order: H6, H9, H1, H10, H8, H4, H3, H7, H5. Extra: H2

public static String removeDashes(String phone) {
	String copy = phone;
	int dash = copy.indexOf("-");
	while (dash != -1) {
		copy = copy.substring(0, dash) + copy.substring(dash + 1);
		dash = copy.indexOf("-");
	}
	return copy;
}

Extra strip: copy = copy.substring(0, dash) + copy.substring(dash);. copy.substring(dash) still starts with the dash, so the dash is never removed and the loop never ends.