我不知道这段代码有什么问题。当我输入正确nomatric
的匹配项时,它会显示正确但也会显示错误消息。
怎么了?
public void Search(int nomatric) {
for (int i = 0; i < student.length; i++) {
if (student[i].matrix == nomatric) {
System.out.printf("%-25s%-25s%-25s%-25s%-25s\n", "Matric", "Name", "Course work", "Final exam", "Grade");
System.out.printf("%-20d %-20s %-20.2f %-20.2f %-20s", student[i].matrix, student[i].name, student[i].coursework, student[i].finalexam, student[i].grade);
System.out.println();
}
}
System.out.println("Cannot find the matric number!!!");
System.out.println();
}