题解 | #统计成绩#

统计成绩

http://www.nowcoder.com/practice/cad8d946adf64ab3b17a555d68dc0bba

import java.util.Arrays;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int x1 = sc.nextInt();
        float a[] = new float[x1];
        float b[] = new float[x1];  //数组的副本,用于排序,其实不用这个副本也行
        float sum = 0;
        for(int i = 0;i<a.length;i++){
            a[i] = sc.nextFloat();
            sum = sum + a[i];
        }
        for(int i = 0;i<a.length;i++){
            b[i] = a[i];
        }
        Arrays.sort(b);   //这里偷懒了,直接使用了排序函数
        System.out.printf("%.2f %.2f %.2f",b[4],b[0],sum/x1);
    }
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务