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

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

小白求問,下面的程序由無參帶返回值方法變成無參無返回值方法,該怎么改?

小白求問,下面的程序由無參帶返回值方法變成無參無返回值方法,該怎么改?

慕數據3565510 2017-05-10 17:19:22
package com.imooc;public class Demo2 {? ??? ? //完成 main 方法? ? public static void main(String[] args) {? ? ? ??? ? ? ? // 創建對象,對象名為hello? ? Demo2 hello = new Demo2();?? ? ? ??? ? ? ? // 調用方法并將返回值保存在變量中? ? ? ? int maxScores=hello.maxAges();? ? ? ?? // 輸出最大年齡 System.out.println("最大年齡為:" + maxScores);? }? ? public int maxAges(){? ? ? ? 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;? ? } }
查看完整描述

2 回答

已采納
?
驚人三明治

TA貢獻14條經驗 獲得超13個贊

package com.imooc;

public class Demo2 {

? ??

? ? //完成 main 方法

? ? public static void main(String[] args) {

? ? ? ??

? ? ? ? // 創建對象,對象名為hello

? ? Demo2 hello = new Demo2();?

? ? ? ??

? ? ? ? // 調用方法并將返回值保存在變量中

? ? ? ? //int maxScores=hello.maxAges();

? ? ? ??hello.maxAges();

// 輸出最大年齡

//System.out.println("最大年齡為:" + maxScores);?

}

? ? public void maxAges(){

? ? ? ? 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];}

? ? ? ? }

? ? ? ? System.out.println("最大年齡為:" + max);?

? ? }



}


查看完整回答
1 反對 回復 2017-05-11
?
heart_

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

把int改成void就行
查看完整回答
反對 回復 2017-05-10
  • 2 回答
  • 0 關注
  • 1561 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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