私のプログラムは、ユーザからの数値の配列をとり、その数を平均と標準偏差で計算します。私は標準偏差の部分に問題があります。私がこれを正しく実行しているかどうかはわかりません。ここで私が持っているものです。ユーザ定義の配列の標準偏差の計算と出力
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
System.out.println("How many numbers do you want to calculate?");
int n = scan.nextInt();
double a[] = new double[(int) n]; // casting n to a double
double sum = 0.0;
double sd = 0.0;
int ifLoop = 0;
System.out.println("Fill in the values for all " + n + " numbers.");
for(int i = 0; i < a.length; i++)
{
a[i] = scan.nextDouble();
sum = sum + a[i];
ifLoop++;
if(ifLoop == a.length)
{
sd = sd + Math.pow(a[i] - (sum/a.length), 2); //THIS IS WHERE I NEED HELP
}
}
System.out.println("The Mean of the " + n +" numbers is " + sum/a.length); // this line finds the average
System.out.println("The Standard Deviation of the " + n + " numbers is " + sd);
}
例入力: 30.7 は190.9 出力:4つの数字の 平均は61.65 ある4つの数字の標準偏差は2270.5225である私は、これは知っています間違っているのは2270.5225であり、標準偏差の式を正しく実装する方法がわかりません。どんな助力も非常に感謝しています。
これは役に立たない。 –