public class YY { private int f(){ int[] s={18,23,21,19,25,29,17}; int max=0; for(int i=0;i<s.length;i++){ if(max<s[i]) max=s[i]; return max; } } public static void main(String[] args){ YY pp=new YY(); pp.f(); System.out.println("最大年龄为:"+pp.f()); } }
1 回答
wl_ht
TA贡献2条经验 获得超1个赞
private int f();这个方法缺少返回值,将return max;挪出来放到for循环后边;如下:
private int f() {
int[] s = { 18, 23, 21, 19, 25, 29, 17 };
int max = 0;
for (int i = 0; i < s.length; i++) {
if (max < s[i])
max = s[i];
}
return max;
}
添加回答
举报
0/150
提交
取消