Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Reads in a sequence of real numbers and computes their average.
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