/****************************************************************************** * Name: Reference Solution * NetID: ref * Precept: P00 * * Description: Reads in integers from StdIn and outputs their average. * Stop reading either when the value 999 is input or when * there is no more input. ******************************************************************************/ public class Rainfall { public static void main(String[] args) { int STOP = 999; double total = 0.0; int count = 0; // read from stdin while(!StdIn.isEmpty()) { // get the raindfall value int value = StdIn.readInt(); // done if value == STOP value if (value == STOP) break; // remove negatives if (value < 0) value = 0; // update values total += value; count++; } // if no input, don't divide by 0 if (count == 0) count = 1; // output solution StdOut.printf("%.2f", total/count); } }