我想按出生年份降序排列我的数组。我的数组有两个其他元素,它们是字符串类型的。因此,例如,出生在最早年份(例如 1939 年)的人将在顶部,然后以此类推。
这是我的代码:
import java.util.*;
public class StudentInformationTest
{
public static void main (String [] args){
StudentInformation[] studentInfo = new StudentInformation[10];
studentInfo[0] = new StudentInformation("Student A",1971, "BSc FDIT");
studentInfo[1] = new StudentInformation("Student B",1964, "BSc FDIT");
studentInfo[2] = new StudentInformation("Student C",1996, "BSc FDIT");
studentInfo[3] = new StudentInformation("Student D",1939, "BSc FDIT");
studentInfo[4] = new StudentInformation("Student E",1945, "BSc FDIT");
studentInfo[5] = new StudentInformation("Student F",1991, "BSc FDIT");
studentInfo[6] = new StudentInformation("Student G",1987, "BSc FDIT");
studentInfo[7] = new StudentInformation("Student H",1968, "BSc FDIT");
studentInfo[8] = new StudentInformation("Student I",1968, "BSc FDIT");
studentInfo[9] = new StudentInformation("Student J",1973, "BSc FDIT");
printInfo(studentInfo);
printAge(studentInfo);
}
public static void printInfo(StudentInformation studentInfo[]){
for(int i = 0; i < studentInfo.length; i++){
System.out.println(studentInfo[i].getStudentName() + " " + studentInfo[i].getBirthDate() + " " + studentInfo[i].getProgrammeOfStudy());
}
System.out.println();
}
}
}
一旦我设法按降序打印出生年份,我还需要显示学生姓名和他们正在做的大学模块。我知道其他问题已经被问到如何做到这一点,但我无法看到其他对象。这是一堂课,所以请原谅我的代码中的任何错误。