title: standard deviation of any sized array java
body: <p>How to calculate the standard divination of an array in Java? As you can see I have already calculated the mean, and I know that at the end I will have to divide by the sample size minus 1 (n-1) and square that number. The problem I'm having is how to take every number and calculate how far it is away from the mean, then square that number. I know I could do every number from the data set separately but there has to be an easier way. Any help would be appreciated, here's my code.</p>
  <pre><code>public class CalculateArray
  {
  
      public static void main(String[] args)
      {
          int [] numbers = new int[]{1,2,3,4,5,6,7,8,9};
  
          int sum = 0;
          int max = 0;
          int min = numbers[0];
          double sd = 0;
      
          for(int i=0; i&lt;numbers.length; i++)
          {
              sum = sum + numbers[i];
          }
  
          double average = sum / numbers.length;
  
          System.out.println(&quot;Average value is : &quot; + average);
  
          for(int i=0; i&lt;numbers.length; i++)
          {
              if(numbers[i] &gt; max)
              {
                  max = numbers[i];
              }
          }
  
          System.out.println(&quot;max number is : &quot; + max);
  
          for(int i=0; i&lt;numbers.length; i++)
          {
              if(numbers[i] &lt; min)
              {
                  min = numbers[i];
              }
          }
  
          System.out.println(&quot;min number is : &quot; + min);
  
          for (int i=0; i&lt;numbers.length;i++)
          {
             //this is where im having problems
             sd = ???
          }
  
          double standardDeviation = math.sqrt(sd/(numbers.length-1));
  
          System.out.println(&quot;The standard deviation is : &quot; + standardDeviation);
      }
  }
  </code></pre>