慕數據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);?
? ? }
}
添加回答
舉報
0/150
提交
取消