idk如果我必须在循环中或循环中获得标准。也可以帮助我理解为什么我在循环内或外出它并且有什么区别。我也知道在这种情况下的标准偏差公式将是(输入 - 平均值)^ 2为第一个然后++为每个值然后添加所有那个并除以计数然后平方根。我只是不完全确定如何写它和把它放在哪里
import java.util.Scanner;
public class readFromKeyboard {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String inStr = input.next();
int n;
int count=0;
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
double average=0;
int sum;
double deviation = 0;
while (!inStr.equals("EOL")) {
count++;
n = Integer.parseInt(inStr);
min = Math.min(min, n);
max = Math.max(max, n);
System.out.printf("%d ", n);
inStr = input.next();
average += n;
}
average = average/count;
System.out.println("\n The average of these numbers is " + average);
System.out.printf("The list has %d numbers\n", count);
System.out.printf("The minimum of the list is %d\n", min);
System.out.printf("The maximum of the list is %d\n", max);
input.close();
}
}
答案 0 :(得分:1)
鉴于您已经计算了average
,现在您可以为每个数字计算standard deviation
。
sd[]
以存储standard deviation
。sd[i] = (average - input_i) ^ 2
计算variance
:
standard deviation
中的每个sd[]
,添加到变量temp
temp
除以输入总数计算population standard deviation
:
variance