/****************************************************************************** * This program the std. dev. of a list of float values on STDIN. * * Copyright © 2017 Richard Lesh. All rights reserved. *****************************************************************************/ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.pureprogrammer.Utils; public class StandardDeviation { public static void main(String[] args) { String line; double total = 0; List samples = new ArrayList<>(); while ((line = Utils.getline()) != null) { double d = Utils.stodWithDefault(line, 0.0); samples.add(d); total += d; } final int COUNT = samples.size(); if (COUNT > 0) { final double AVERAGE = total / COUNT; double deviation = 0.0; for (double sample : samples) { deviation += Math.pow(sample - AVERAGE, 2.0); } System.out.println(Utils.format("{0:.16g}", Math.sqrt(deviation / COUNT))); } } }