Java programming standard deviation error in code
<p>My standard deviation is way off. When I enter:
2 4 4 4 5 5 7 9 n</p>

<p>I don't get 2. This is my code. I believe everything checks out so I don't understand why I keep getting 1.8284791953425266 instead of 2 :  </p>

<pre><code>import java.util.Scanner;

public class stocks {

  public static void main(String[] args) {

     Scanner in = new Scanner(System.in);
     double currentNum = 0;
     double numtotal = 0;
     int count = 0;
     double mean = 0;
     double square = 0, squaretotal = 0, sd = 0;

     System.out.println("Enter a series of double value numbers, ");
     System.out.println("Enter anything other than a number to quit: ");

     while (in.hasNextDouble()) 
     {

         currentNum = in.nextDouble();
         numtotal = numtotal + currentNum;

         count++;
         mean = (double) numtotal / count;
         square = Math.pow(currentNum - mean, 2.0);
         squaretotal = squaretotal + square; 
         sd = Math.pow(squaretotal/count, 1/2.0);
     }

     System.out.println("The mean is: " +mean);
     System.out.println("The standard deviation is: " +sd);

     }


 }
</code></pre>
