import java.util.Scanner;
public class Test
{
public static void main(String[] args)
{
System.out.print("Enter ten numbers: ");
Scanner input = new Scanner(System.in);
double[] numbers = new double[10];
for(int i = 0; i < numbers.length; i++)
numbers[i] = input.nextDouble();
System.out.println("The mean is " + mean(numbers));
System.out.println("The standard deviation is " + deviation(numbers));
}
public static double mean(double[] x)
{
double sum = 0;
for(double tmp: x)
sum += tmp;
double mean = sum / x.length;
return mean;
}
public static double deviation(double[] x)
{
double sum = 0;
for(int i = 0; i < x.length; i++)
sum = sum + Math.pow((x[i] - mean(x)), 2);
double deviation = Math.pow((sum / (x.length - 1)), 0.5);
return deviation;
}
}
6-11 编程练习题答案
最新推荐文章于 2022-04-25 15:44:55 发布