huzhihui1 2017-12-03 08:00 采纳率: 100%
浏览 1705
已采纳

关于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语句,这是为什么?

  • 写回答

2条回答 默认 最新

  • mvpxgx 2017-12-03 08:06
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器