题解 | 牛牛的数学作业
牛牛的数学作业
https://www.nowcoder.com/practice/6f5d239c34a7429cb325a3d836abc342
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
for(int i =0; i<T ; i++){
List<Integer> list = new ArrayList<>();
int sum = 0;
int n = in.nextInt();
for(int j =0; j< n; j++){
int a = in.nextInt();
list.add(a);
sum += a;
}
System.out.print(Collections.max(list)-Collections.min(list)+" ");
double b = (double)sum/n;
double sumavg = 0;
for(int k=0; k<list.size(); k++){
sumavg += Math.pow(list.get(k)-b,2);
}
System.out.println(String.format("%.3f", sumavg/n));
}
}
}
华为HUAWEI工作强度 1380人发布