Access Millions of academic & study documents

Solution11

Content type
User Generated
Subject
Computer Science
Type
Homework
Showing Page:
1/2
import java.util.Scanner;
public class rainfall{
public static void main(String []args){
float rainfall = 0.0f;
float maxRainfall = 0.0f;
float monthRainfall = 0.0f;
int months = 0;
float averageRainfall = 0.0f;
Scanner reader = new Scanner(System.in); // Reading from System.in
while (true)
{
System.out.print("Enter rainfall for month#"+(months+1)+"(or -1
to stop):");
monthRainfall = reader.nextFloat();
if (monthRainfall == -1) break;
months +=1;
rainfall += monthRainfall;
if (monthRainfall>maxRainfall) {
maxRainfall = monthRainfall;
}
}
averageRainfall = rainfall/months;
System.out.println("Total Months:" + months);
System.out.print("Total Rainfall:" );
System.out.printf("%.2f",rainfall);
System.out.println("");
System.out.print("Average Rainfall:");
System.out.printf("%.2f",averageRainfall);
System.out.println("");
System.out.print("Maximum Rainfall:" );
System.out.printf("%.2f",maxRainfall);
System.out.println("");
reader.close();
}
}

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/2

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
import java.util.Scanner; public class rainfall{ public static void main(String []args){ float rainfall = 0.0f; float maxRainfall = 0.0f; float monthRainfall = 0.0f; int months = 0; float averageRainfall = 0.0f; Scanner reader = new Scanner(System.in); // Reading from System.in while (true) { System.out.print("Enter rainfall for month#"+(months+1)+"(or -1 to stop):"); monthRainfall = reader.nextFloat(); if (monthRainfall == -1) break; months +=1; rainfall += monthRainfall; if (monthRainfall>maxRainfall) { maxRainfall = monthRainfall; } } averageRainfall = rainfall/months; System.out.printl ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4