Arrays 从数字列表中查找标准偏差(用户输入)

Arrays 从数字列表中查找标准偏差(用户输入),arrays,math,java.util.scanner,standard-deviation,Arrays,Math,Java.util.scanner,Standard Deviation,我试图寻找一个示例,说明如何从用户输入的数字列表中找到标准偏差。我想知道是否有人能解释一下如何从扫描仪上找到一系列数字的标准偏差。任何建议都很好 -提前谢谢当然可以-这样就可以了 package statistics; /** * Statistics * @author Michael * @link http://stackoverflow.com/questions/11978667/online-algorithm-for-calculating-standrd-deviatio

我试图寻找一个示例,说明如何从用户输入的数字列表中找到标准偏差。我想知道是否有人能解释一下如何从扫描仪上找到一系列数字的标准偏差。任何建议都很好


-提前谢谢

当然可以-这样就可以了

package statistics;

/**
 * Statistics
 * @author Michael
 * @link http://stackoverflow.com/questions/11978667/online-algorithm-for-calculating-standrd-deviation/11978689#11978689
 * @link http://mathworld.wolfram.com/Variance.html
 * @since 8/15/12 7:34 PM
 */
public class Statistics {

    private int n;
    private double sum;
    private double sumsq;

    public void reset() {
        this.n = 0;
        this.sum = 0.0;
        this.sumsq = 0.0;
    }

    public synchronized void addValue(double x) {
        ++this.n;
        this.sum += x;
        this.sumsq += x*x;
    }

    public synchronized double calculateMean() {
        double mean = 0.0;
        if (this.n > 0) {
            mean = this.sum/this.n;
        }
        return mean;
    }

    public synchronized double calculateVariance() {
        double variance = 0.0;
        if (this.n > 0) {
            variance = Math.sqrt(this.sumsq-this.sum*this.sum/this.n)/this.n;
        }
        return variance;
    }

    public synchronized double calculateStandardDeviation() {
        double deviation = 0.0;
        if (this.n > 1) {
            deviation = Math.sqrt((this.sumsq-this.sum*this.sum/this.n)/(this.n-1));
        }
        return deviation;
    }
}

从用户输入中获取数字或从数字列表中获取标准偏差有困难吗?这是两个不同的问题,需要在这里分开。如果您正在进行计算(即每次扫描新数字时都会更新),请查看标准偏差的指数加权移动平均(EWMA)公式,因为这些公式通常有一个更易于“在线”更新的形式.我想知道如何从用户输入中获取它。我希望能解释一下程序的工作原理,而不仅仅是代码。