gpt4 book ai didi

java - ArrayList 的标准偏差

转载 作者:行者123 更新时间:2023-11-29 06:30:01 24 4
gpt4 key购买 nike

<分区>

此代码应该找到 Standard deviation ArrayList 中的随机整数。但是,我的标准偏差代码没有显示正确的结果。它显示了预期的另一个数字。

我做错了什么?

import java.io.*;
import java.util.*;

public class Assignment4 {
public static void main(String[] args)
{
ArrayList<Integer> values = new ArrayList<Integer>();
int count = 0;
int total = 0;
Random r = new Random();

for (int i = 1; i <= 10; i++) {
values.add(r.nextInt(90)+ 1);

System.out.println(values);

}

System.out.println(mean(values));
System.out.println(sd(values));
}

public static double mean (ArrayList<Integer> table)
{
int total = 0;

for ( int i= 0;i < table.size(); i++)
{
int currentNum = table.get(i);
total+= currentNum;
}
return total/table.size();
}

public static double sd (ArrayList<Integer> table)
{
double mean= mean(table);
double temp =0;
for ( int i= 0; i <table.size(); i++)
{
temp= Math.pow(i-mean, 2);
}

return Math.sqrt(mean( table));
}

public static void selectionSort(ArrayList<Integer> table)
{
int count = table.size();
for(int pos = 0; pos < count - 1; pos++)
{
int locMin = pos;
for(int i = pos + 1; i < count; i++)
{
if(table.get(i) < table.get(locMin))
locMin = i;
}

int temp = table.get(pos);
table.set(pos, table.get(locMin) );
table.set(locMin, temp);
}
}
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com