title: Calculating sample variance in Java, but is giving the wrong answer when inserting similar numbers
body: <pre><code>import java.util.ArrayList;
  
  public class Variance {
  // Copy here sum from exercise 63 
  public static int sum(ArrayList&lt;Integer&gt; list) {
      int sum = 0;        
      for(int i=0; i&lt;list.size(); i++ ){
          sum = sum + list.get(i) ;
      }
      return sum;
  }
  
  // Copy here average from exercise 64 
  public static double average(ArrayList&lt;Integer&gt; list) {  
      double average = sum(list)/list.size();
      return average;
  }
  
  public static double variance(ArrayList&lt;Integer&gt; list) {
      // write code here
     double sumMinusAverage = sum(list) - average(list);
     return sumMinusAverage * sumMinusAverage / (list.size()-1);
  }
  
  public static void main(String[] args) {
      ArrayList&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;();
      list.add(3);
      list.add(2);
      list.add(7);
      list.add(2);
  
      System.out.println("The variance is: " + variance(list));
  
  }
  
  }
  </code></pre>
  
  <p>The program is calculating variance. But when when the list contains the same numbers etc 1-s. The program says the variance is 3, but the answer should be 0.</p>
  
  <p>Can someone give me some direction.</p>