-1

I cant seem to figure out how exactly to find the standard deviation using what i have. the thing that is confusing me is really the whole standard deviation equation and how to exactly put it into code.

import java. util.Scanner;

public class StandardDeviation
{
 public static void main (String[] args)
 {
   int array;
   float sum = 0;
   float mean;

   Scanner scan = new Scanner(System.in);
   System.out.println("Enter wanted array length:");
   array = scan.nextInt();

   float[] numbers = new float[array];

   System.out.println("The size of the array: " + numbers.length);

   for (int index = 0; index < numbers.length; index++)
   {
     System.out.print("Enter number " + (index+1) + ": ");
     numbers[index] = scan.nextFloat();
   }

   for (float i : numbers)
   {
     sum += i;
   }
   mean = sum/numbers.length;
   System.out.println("The mean is: " + mean);

 }

}

Compass
  • 5,867
  • 4
  • 30
  • 42
  • Try a statistics site? Google 'standard deviation', (About 31,100,000 results)? – Martin James Feb 12 '15 at 18:26
  • Do you mean to say you don't understand the concept of standard deviation, or that you don't know how to apply the pretty clearly defined explanation in java? Something about this sounds like homework – Kai Qing Feb 12 '15 at 18:27
  • and what is the problem you are facing in Java ? , check here [how to calculate Standard Deviation](http://www.mathsisfun.com/data/standard-deviation.html) – Neeraj Jain Feb 12 '15 at 18:45

1 Answers1

0

You already have the mean, which is the first step in finding the standard deviation.

First, you loop through your array of numbers. You subtract the number from the mean, then square the answer. Add the squared answers together.

Next, divide your squared answer sum by the length of your array of numbers, minus 1.

Finally, take the square root of the result of the last step.

  1. Sum (x - mean) * (x - mean)
  2. Sum from step 1. / (length - 1)
  3. Square root of the result from step 2.

Math.pow(number, 0.5D) gives you the square root of a double.

Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111