亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

哪里錯誤,請問怎么修改呢?

哪里錯誤,請問怎么修改呢?

qq_你今天真漂亮_04247659 2016-12-11 20:40:58
public class helloworld {? ??? ? //完成 main 方法? ? public static void main(String[] args) { helloworld hello = new helloworld();?? ? ? ? int maxScore=hello.getMaxAge(); // 輸出最大年齡 System.out.println("最大年齡為:" + maxScore);? }public int getMaxAge(){ ? ? ? 錯誤原因:Multiple markers at this line - This method must return a result of? type int - This method must return a result of? type int int []ages={18,23,21,19,25,29,17};? ? int max=ages[0];? ? for(int i=0;i<ages.length;i++){? ? ? ? if(ages[i]>max);? ? ? max=ages[i] ;? ? ? return max;? ? }哪里錯了呢,怎么修改
查看完整描述

3 回答

已采納
?
Bran_Zuo

TA貢獻3條經驗 獲得超1個贊

for循環里執行return只是退出循環,但是getMaxAge方法并沒有返回語句,應將return語句放在for循環外

public?class?helloworld?{
????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=ages[0];
????????for(int?i=0;i<ages.length;i++)
????????{
????????????if(ages[i]>max);
???????????????max=ages[i]?;
????????}
????????return?max;
????}
}


查看完整回答
反對 回復 2016-12-12
?
Its_forever

TA貢獻361條經驗 獲得超328個贊

? ? ? return max;放到括號之后。

public?int?getMaxAge(){

int?[]ages={18,23,21,19,25,29,17};
????int?max=ages[0];
????for(int?i=0;i<ages.length;i++){
????????if(ages[i]>max);
??????max=ages[i]?;
??????
????}
????return?max;
????}


查看完整回答
反對 回復 2016-12-11
?
張旖旎

TA貢獻1條經驗 獲得超0個贊

缺少返回值吧。在你定義的public int getMaxAge()這個方法里。你可以return一個要的數據就不會錯了

查看完整回答
反對 回復 2016-12-11
  • 3 回答
  • 0 關注
  • 1950 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號