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,我要输出的是数组中的最大值?求解答
丶小布偶
浏览 1102回答 1
1回答
ziom
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;
}
}