Generally you don't know number of values to print up-front (but in your case it's 4). So it is easier to print separator before
instead of after
. No if
s:
String sep="";
for (i = 0; i < NUM_VALS; i++) {
System.out.print(sep + hourlyTemp[i]);
sep=", ";
}
Trick is - first time there is nothing to separate hence separator is empty, later - ", "
;
Fits into register, saves branch predictor's work. Calculating if (i == last_value)
is not 0 cost as well.