定义一个学生类,再在main中传值输出呗
public class Grade {
public static void main(String[] args) {
Student[] students = {new Student("王岚",85,90,75),
new Student("刘东",88,87,78),
new Student("张敏",78,86,80),
new Student("赵甜",95,80,82),
new Student("刘洋",90,95,85)};
for (int i = 0; i < students.length; i++) {
System.out.println(students[i].name+" "+students[i].chinese+" "+students[i].math+" "+students[i].english+" "+students[i].sum()+" "+students[i].average()+" "+students[i].max()+" "+students[i].min());
students[i].sum();
}
}
}
class Student{
String name;
int chinese;
int math;
int english;
public Student(String name, int chinese, int math, int english) {
this.name = name;
this.chinese = chinese;
this.math = math;
this.english = english;
}
int sum(){
return chinese+math+english;
}
int average(){
return (chinese+math+english)/3;
}
int max(){
int max = chinese;
if (math > max) {
max = math;
}
if (english > max) {
max = english;
}
return max;
}
int min(){
int min = chinese;
if (math < min) {
min = math;
}
if (english < min) {
min = english;
}
return min;
}
}
挺简单的,还是自己写一下,再看别人的