public class 计算成绩 {
/**
* 计算成绩的最大值,最小值,平均分和标准差
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = new int[5];
System.out.println("请输入十个人的成绩:");
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.nextInt();
}
int max = arr[0];//最大值
int min = arr[0];//最小值
for (int i = 0; i < arr.length; i++) {
if (arr[i]>max){
max = arr[i];
}
if (arr[i]<min){
min = arr[i];
}
}
int ave = 0;//平均分
for (int i = 0; i < arr.length; i++) {
ave += arr[i];
}
ave/=arr.length;
int diff = 0;//标准差
for (int i = 0; i < arr.length; i++) {
diff += Math.pow(arr[i]-ave,2);
}
diff/=arr.length;
int a =(int) Math.sqrt(diff);
System.out.printf("最大值为:%d,最小值为:%d,平均值为:%d,标准差:%d",max,min,ave,a);
}
}
计算最大值,最小值,平均分和标准差
最新推荐文章于 2023-06-16 14:08:15 发布