[Java] 纯文本查看 复制代码
import java.util.*;[/align]
public class Ceshistudent {
public static void main(String[] args) {
ArrayList<Student> co=new ArrayList<>();
for (int i =1; i <= 5; i++) {
Scanner sc=new Scanner(System.in);
System.out.println("请输入第"+i+"个学员信息:");
String a=sc.next();
System.out.println("请输入成绩:");
int b=sc.nextInt();
Student s1=new Student(a,b);
co.add(s1);
}
Student max=co.get(0);
Student min=co.get(0);
int z=0;
for (int i = 0; i < co.size(); i++) {
if (co.get(i).getChengji()>max.getChengji()){
max=co.get(i);
}
if (co.get(i)<min){
min=co.get(i);
}
z=z+=co.get(i).getChengji();
}
double p=z/co.size();
System.out.println("成绩最高的学员是:"+max.getName()+"成绩为"+max.getChengji()+"分");
System.out.println("成绩最低的学员是:"+min.getName()+"成绩为"+min.getChengji()+"分");
System.out.println("平均分:"+p);
}
}