class HelloWorld
{
private int maxScore
public static void main(String[] args) {
HelloWorld hello = new HelloWorld();
int maxScore=hello.getMaxAge();
System.out.println("最大年龄为:" + maxScore);
}
public int getMaxAge() {
int[] ages={18,23,21,19,25,29,17};
int max =18;
for(int i = 0;i<ages.length;i++){
if(max<ages[i]){
max=ages[i];
} }
return maxScore;
}
}
为什么最后输出是0,我要输出的是数组中的最大值?求解答
1 回答
已采纳
ziom
TA贡献948条经验 获得超1109个赞
class HelloWorld { private int maxScore; public static void main(String[] args) { HelloWorld hello = new HelloWorld(); int maxScore=hello.getMaxAge(); System.out.println("最大年龄为:" + maxScore); } public int getMaxAge() { int[] ages={18,23,21,19,25,29,17}; int max =18; for(int i = 0;i<ages.length;i++){ if(max<ages[i]){ max=ages[i]; } } // return maxScore; 此处应返回max return max; } }
添加回答
举报
0/150
提交
取消