水墨


私信TA

用户名:dotcpp0690329

访问量:351

签 名:

等  级
排  名 10188
经  验 1045
参赛次数 0
文章发表 3
年  龄 0
在职情况 学生
学  校 四川工商学院
专  业

  自我简介:

解题思路:


    先定义一个学生类Student,并且设置学号,姓名,三科的成绩,并给出输入的这些数据的方法,然后先根据输入的Student类的数据来将平均数挨个输出,之后比对三科成绩最高分的学生,然后将之输出。具体参考下面的代码。


注意事项:

参考代码:

import java.util.Scanner;

 

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        Strudent [] st = new Strudent[n];

        int [] arr1 = new int[n];

        int [] arr2 = new int[n];

        int [] arr3 = new int[n];

        for(int i=0;i<n;i++){

             st[i] = new Strudent(sc.next(),sc.next(),sc.nextInt(),sc.nextInt(),sc.nextInt());

             arr1[i] = st[i].a;

             arr2[i] = st[i].b;

             arr3[i] = st[i].c;

        }

        int sum1=0,sum2=0,sum3=0;

        for(int i=0;i<n;i++){

            sum1+=arr1[i];

            sum2+=arr2[i];

            sum3+=arr3[i];

        }

        System.out.print(sum1/n);

        System.out.print(' ');

        System.out.print(sum2/n);

        System.out.print(' ');

        System.out.print(sum3/n);

        System.out.println();

        int a = st[0].a+st[0].b+st[0].c;

        int m=0;

        for(int i=0;i<st.length;i++){

            if(a<(st[i].a+st[i].b+st[i].c)){

                a=(st[i].a+st[i].b+st[i].c);

            }

        }

        for(int i=0;i<st.length;i++){

            if(a==(st[i].a+st[i].b+st[i].c)){

                m=i;

            }

        }

        System.out.println(st[m].id+' '+st[m].name+' '+st[m].a+' '+st[m].b+' '+st[m].c);

    }

}

class Strudent {

    String id;

    String name;

    int a,b,c;

    public Strudent(){};

    public Strudent(String Id, String Name, int A, int B, int C){

        this.id = Id;

        this.name = Name;

        this.a = A;

        this.b = B;

        this.c = C;

    }

 

}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区