我在这个程序中的标准差输出为0,我不知道我做错了什么。我被困在这几个小时,请帮忙。
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
System.out.println("How many numbers do you want to calculate?");
int n = scan.nextInt();
double a[] = new double[(int) n]; // casting n to a double
double sum = 0.0;
double sd = 0.0;
System.out.println("Fill in the values for all " + n + " numbers.");
for(int i = 0; i < a.length; i++)
{
a[i] = scan.nextDouble();
sum = sum + a[i];
}
double average = sum/a.length;
for(int i = 0; i < a.length; i++)
{
a[i] = Math.pow((a[i]-average),2); // need help here
}
System.out.println("The Mean of the " + n +" numbers is " + average);
System.out.println("The Standard Deviation of the " + n + " numbers is " + sd);
}