I need to print to 2 decimal places and I'm trying to use the printf method, but for some reason I keep getting an error. I've looked through my code, but unless I'm missing a small detail, it looks okay to me.
float sum = 0; float avg = 0; double[] rain = {0, 1.9, 1.5, 1.2, 1.1, 0.5, 0.03, 1.0}; //Calculate sum of rain. for (int i = 1; i <= 7; i++) { sum += rain[i]; } //Calculate average of rain avg = (sum / 7); //Printout //Titles System.out.println("Day\t " + " Rain"); //rainfall and days for (int j = 1; j <= 7; j++) { System.out.println(j + "\t " + rain[j]); } //avg rainfall System.out.printf("The average rainfall for the week is: %.2f" + avg); } }