Average & Max number Method


Submit solution

Points: 45 (partial)
Time limit: 1.0s
Memory limit: 64M

Authors:
Problem types

題目說明

根據使用者存入陣列的5個整數,設計兩個副程式averagefindMax,並印出結果。

  • average方法:計算5個數的平均後回傳答案(四捨五入至第二位)
  • findMax方法:找出5個數的最大值後回傳答案

請完成註解TODO部分,使程式符合題目要求。
⚠️ 請依照程式模板進行撰寫,若人工檢查時發現結構變更將無法得分。

import java.util.Scanner;
public class averagemax {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int[] array = new int[5];
        for (int i = 0; i < 5; i++) {
            array[i] = input.nextInt();
        }
        input.close();
        System.out.printf("average is %.2f",average(array));//%.2f 浮點數四捨五入至第二位
        System.out.print("\nmax number is "+findMax(array));

    }

    // TODO:請實作findMax方法,回傳最大值(int)

    // TODO:請實作average方法,回傳平均數(double) 


}

輸入

五個整數存入陣列

輸出

average is (平均數)
max number is (最大值)

範例輸入 #1

4 5 2 1 4

範例輸出 #1

average is 3.20
max number is 5

範例輸入 #2

-12 6 -88 41 1

範例輸出 #2

average is -10.40
max number is 41

Comments

There are no comments at the moment.