关于return返回值的问题,求大神解释

public class Student {
private String name;
private int age;
private int score;
public Student() {
super();
}
public Student(String name, int age, int score) {
this.name = name;
this.age = age;
this.score = score;
}
。。。。。。。
}
public class StudentsTool {
public int getMaxScore(Student[] arr) {//:获取学生成绩的最高分
int max=0;
for (int i = 0; i < arr.length-1; i++) {
Student student = arr[i];
int score=student.getScore();
if(score>max) {
max=score;
}
}
System.out.println("学生最高成绩为:"+max);
return max;
}
public class TestStudentTool {
public static void main(String[] args) {
// TODO Auto-generated method stub
Student s1=new Student("小明",22,68);
Student s2=new Student("小强",21,70);
Student s3=new Student("小翟",22,90);
Student s4=new Student("小杨",25,59);
Student s5=new Student("小刘",24,48);
Student[] arr2={s1,s2,s3,s4,s5};
StudentsTool a=new StudentsTool();
a.getMaxScore(arr2);
此程序中函数getMaxScore()里面的return后面跟的返回参数对程序一点影响都没有,输出全靠System语句,这是为什么?

因为输出在方法体中getMaxScore,在return前面,你也没用变量接收啊

如果您想使用这个返回值,需要定义一个变量接收,类似:

int result;
//Other codes
result  = a.getMaxScore(arr2);

题目中的写法直接在类成员函数中输出了max值,是有点别扭,如果不习惯,可以用上面的方法接收到该值后再输出。
效果是一样的。