標準偏差を見つけるためのコードが間違っています。私のコードは、ユーザー入力からの標準偏差を見つけるはずです。私は数字1 2 3をタイプし、この数字セットの標準偏差は1ですが、どこが間違っていたのですか?また、私は未使用の変数の束がそれらを気にしないことを知っています。標準偏差の計算に何が問題なのですか?
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 i;
int count=0;
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
double average=0;
int sum;
double deviation = 0;
int total;
int temp = 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;
temp += Math.pow(n - average, 2);
}
deviation = temp
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);
System.out.printf("The standard deviation of the list is %d\n", temp);
input.close();
}
}
ループ内では、「平均」は実際には平均ではなく、累積合計です。私はあなたが実際の平均を持っている後に偏差を計算する必要があると思う –
あなたのコードはあなたがそれを書いたものを正確にやっているが、標準偏差を計算するあなたの方法はかなり間違っています。このページを読んでコードを書き直してください(かなり)[標準偏差の計算](https://www.strchr.com/standard_deviation_in_one_pass) –
私のコードは何ですか?私はそれが最初の入力番号を取って平均を減算してそれらを二乗すると思った –