题解 | #统计成绩#
统计成绩
http://www.nowcoder.com/practice/cad8d946adf64ab3b17a555d68dc0bba
解题思路
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sin = new Scanner(System.in);
// 获取输入
int n = sin.nextInt();
double[] d = new double[5];
int i = 0;
while(sin.hasNextDouble()){
d[i++] = sin.nextDouble();
}
// 输出 最高分 最低分,平均分
System.out.println(String.format("%.2f",getMax(d)) + " " + String.format("%.2f",getMin(d)) + " " + String.format("%.2f",getAvg(d) / n));
}
public static double getMax(double[] d){
double dn = 0.0;
for(double d1:d){
if(d1 > dn){
dn = d1;
}
}
return dn;
}
public static double getMin(double[] d){
double dn = 100.0;
for(double d1:d){
if(d1 < dn){
dn = d1;
}
}
return dn;
}
public static double getAvg(double[] d){
double dn = 0.0;
for(double d1:d){
dn += d1;
}
return dn;
}
}