Hey guys I'm having trouble figuring out 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, heres my 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<numbers.length; i++)
{
sum = sum + numbers[i];
}
double average = sum / numbers.length;
System.out.println("Average value is : " + average);
for(int i=0; i<numbers.length; i++)
{
if(numbers[i] > max)
{
max = numbers[i];
}
}
System.out.println("max number is : " + max);
for(int i=0; i<numbers.length; i++)
{
if(numbers[i] < min)
{
min = numbers[i];
}
}
System.out.println("min number is : " + min);
for (int i=0; i<numbers.length;i++)
{
//this is where im having problems
sd = ???
}
double standardDeviation = math.sqrt(sd/(numbers.length-1));
System.out.println("The standard deviation is : " + standardDeviation);
}
}