package hello;public class test8 { ? ? ? ?//完成 main 方法 ? ?public static void main(String[] args) { ? ? ? ? ? ? ? ?// 創(chuàng)建對象,對象名為hello ? ? test8 hello = new test8();? ? ? ? ? ? ? ? ?// 調(diào)用方法并將返回值保存在變量中 ? ? ? ?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(max <= ages[i]){ ? ? ? ? ? ?max = ages[i]; ? ? ? ?} ? ?} ? ? ? ? return max; }
添加回答
舉報
0/150
提交
取消