Reads in a sequence of real numbers and computes their average.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Average | |
{ | |
private Average() { } | |
public static void main( String[] args ) | |
{ | |
int count = 0; | |
double sum = 0.0; | |
while ( !StdIn.isEmpty() ) | |
{ | |
double value = StdIn.readDouble(); | |
sum += value; | |
count++; | |
} | |
double average = sum / count; | |
StdOut.println( "Average is " + average ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment