title: Calculate Standard Deviation using Java?
body: <p>I have an ArrayList of integers: [11, 15, 10, 19, 9, 1, 2, 16]
    and I can't seem to return the right answer.</p>
  
  <p>My code:</p>
  
  <pre><code>static double Q2(ArrayList&lt;Integer&gt; input) {
      Collections.sort(input);
  
      ArrayList&lt;Double&gt; input2 = new ArrayList&lt;&gt;();
      double sum = 0;
      double sum2 = 0;
      double sd = 0;
  
      for (int i = 0; i &lt; input.size(); i++) {
          sum = sum + input.get(i);
      }
  
      double mean = sum / input.size();
  
      for (int i = 0; i &lt; input.size(); i++) {
          input2.add((Math.pow((input.get(i) - mean), 2)));
      }
  
      for (int i = 0; i &lt; input2.size(); i++) {
          sum2 = sum2 + input2.get(i);
      }
  
      double mean2 = sum2 / input2.size();
  
      sd = Math.sqrt(mean2);
  
      return sd;
  </code></pre>
  
  <p>The Expected output should be: 5.998697775350913</p>
  
  <p>My output is : 6.010407640085654</p>
  
  <p>Thank you for your time, much appreciated.</p>