Return the day, from 1 to numDays, with the highest temperature. You may call getTemp(int day), which returns that day's temperature.
If the temperatures are 61, 74, 68, 80, 72, hottestDay(5) returns 4.
10 strips: C1 to C10
} C1public static int hottestDay(int numDays) { C2} C3if (getTemp(day) > bestDay) { C4int bestDay = 1; C5if (getTemp(day) > getTemp(bestDay)) { C6for (int day = 2; day <= numDays; day++) { C7} C8bestDay = day; C9return bestDay; C10Order: C2, C5, C7, C6, C9, C8, C3, C10, C1. Extra: C4
public static int hottestDay(int numDays) {
int bestDay = 1;
for (int day = 2; day <= numDays; day++) {
if (getTemp(day) > getTemp(bestDay)) {
bestDay = day;
}
}
return bestDay;
} Extra strip: if (getTemp(day) > bestDay) {. It compares a temperature to a day number. The best day's temperature is getTemp(bestDay).