public class Test {
public static void main(String[] args) {
System.out.println("请输入10个double类型的数,并以空格隔开:");
Scanner input = new Scanner(System.in);
double[] arr = new double[10];
for (int i = 0; i < 10; i++) {
arr[i] = input.nextDouble();
}
System.out.println(min(arr));
System.out.println(max(arr));
System.out.println("平均数:" + avg(arr));
System.out.println(standard(arr));
}
/**
* 标准差
*/
public static String standard(double[] arr) {
double sum = 0;
double avg = avg(arr);
for (int i = 0; i < arr.length; i++) {
sum = sum + Math.pow((arr[i] - avg), 2);
}
return "标准差:" + Math.sqrt(sum/arr.length);
}
/**
* 平均值
*/
public static double avg(double[] arr) {
double sum = 0;
for (double a : arr) {
sum = sum + a;
}
return sum / arr.length;
}
/**
* 最大值
*/
public static String max(double[] arr) {
Arrays.sort(arr);
return "最大值:" + arr[arr.length-1];
}
/**
* 最小值
*/
public static String min(double[] arr) {
Arrays.sort(arr);
return "最小值:" + arr[0];
}
}