解题思路:
先定义一个学生类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 人评分
哥德巴赫曾猜测 (C语言代码)浏览:994 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:885 |
简单的a+b (C语言代码)浏览:335 |
【排队买票】 (C语言代码)浏览:899 |
WU-判定字符位置 (C++代码)浏览:1395 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:780 |
C语言训练-大、小写问题 (C语言代码)浏览:674 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:553 |
10月月赛题解浏览:536 |
C二级辅导-温度转换 (C语言代码)浏览:540 |