package laba6;

public class example3 {

    // ===== static методы с произвольным количеством аргументов =====

    public static int max(int... values) {
        int m = values[0];
        for (int v : values) {
            if (v > m) m = v;
        }
        return m;
    }

    public static int min(int... values) {
        int m = values[0];
        for (int v : values) {
            if (v < m) m = v;
        }
        return m;
    }

    public static double average(int... values) {
        int sum = 0;
        for (int v : values) {
            sum += v;
        }
        return (double) sum / values.length;
    }

    // демонстрация работы
    public static void main(String[] args) {
        int[] data = {4, 7, 1, 9, 2};

        System.out.println("Работа с varargs:");
        System.out.println("max = " + max(4, 7, 1, 9, 2));
        System.out.println("min = " + min(4, 7, 1, 9, 2));
        System.out.println("avg = " + average(4, 7, 1, 9, 2));

        System.out.println("\nРабота с массивом:");
        System.out.println("max = " + max(data));
        System.out.println("min = " + min(data));
        System.out.println("avg = " + average(data));
    }
}