public class NumTest {
public static void main(String[] args){
double num=0
Scanner s = new Scanner(System.in)
System.out.println("请输入你需要计算的个数:")
int n = s.nextInt()
double[] list=new double[n]
for (int i = 1i <= ni++) {
System.out.println("请输入第"+i+"个数:")
list[i-1]=s.nextDouble()
num+=list[i-1]
}
double mean=num/n
double var=0
for(double d:list){
var+=(d-mean)*(d-mean)
}
System.out.println("方差是:"+var/n)
}
}
public static void main(String[] args) {double[] array = { 1, 2, 3, 4, 5, 6 }
double ave = 0
for (int i = 0i <array.lengthi++)
ave += array[i]
ave /= array.length
double sum = 0
for(int i = 0i<array.lengthi++)
sum += (array[i] - ave) * (array[i] - ave)
sum /= array.length
System.out.println(sum)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)