java 标准偏差函数std_java 怎样计算标准差

importjava.util.*;publicclassExercise8{publicstaticvoidmain(String[]args){Scannerkb=newScanner(System.in);doublevalue,sum=0,mean=0,max=0,min=0,sd=0;intnum;System.out.prin...

import java.util.*;

public class Exercise8{

public static void main(String[]args){

Scanner kb = new Scanner(System.in);

double value,sum=0,mean=0,max=0,min=0,sd=0;

int num;

System.out.print("How many number will input?");

num = kb.nextInt();

double [] a = new double[num];

for(int i=0;i

System.out.print("Value?");

value = kb.nextDouble();

sum+=value;

a[i]=value;

}

max=a[0];

min=a[0];

for(int j=1;j

if (max

max=a[j];

}

else

if(min>a[j]){

min=a[j];

}

}

mean=sum/num;

sd =Math.sqrt(Math.pow((a.length-mean),2)/(num-1));

System.out.println("Sum = "+sum);

System.out.println("Mean = "+mean);

System.out.println("Maximun number ="+max);

System.out.println("Minimum number ="+min);

System.out.println("Standard Deviation ="+sd);

}

}

这里应该怎样计算出标准差

另外为什麼sum的输出会变成7.40999999999999999

展开

你可能感兴趣的:(java,标准偏差函数std)