Return the average score of games 1 through games. You may call getScore(int game), which returns that game's score.
If the scores are 10, 15, 12, average(3) returns 12.333....
8 strips: D1 to D8
for (int g = 1; g <= games; g++) { D1public static double average(int games) { D2} D3return (double) total / games; D4return total / games; D5} D6int total = 0; D7total += getScore(g); D8Order: D2, D7, D1, D8, D6, D4, D3. Extra: D5
public static double average(int games) {
int total = 0;
for (int g = 1; g <= games; g++) {
total += getScore(g);
}
return (double) total / games;
} Extra strip: return total / games;. total / games divides two int values, so the decimal part is lost and it returns 12.0.