Here you can find the source of variance(double[] d)
public static double variance(double[] d)
//package com.java2s; // License as published by the Free Software Foundation. // public class Main { public static double variance(double[] d) { // The variance is equal to the mean of the squares minus the square of the mean // Mean of squares double sum = 0.0; for (int i = 0; i < d.length; i++) sum += Math.pow(d[i], 2); double meanSquares = sum / (double) d.length; // Square of mean sum = 0.0;//from w w w . j a v a 2 s .co m for (int i = 0; i < d.length; i++) sum += d[i]; double squareMean = Math.pow(sum / (double) d.length, 2); return meanSquares - squareMean; } }