001package algs12;
002import stdlib.*;
003import java.util.Arrays;
004
005public class XArrayStatsStatic {
006        public static double min (double[] array) {
007                double theMin = Double.POSITIVE_INFINITY;
008                for (double d : array) {
009                        if (d < theMin) theMin = d;
010                }
011                return theMin;
012        }
013        public static double max (double[] array) {
014                double theMax = Double.NEGATIVE_INFINITY;
015                for (double d : array) {
016                        if (d > theMax) theMax = d;
017                }
018                return theMax;
019        }
020        public static double mean (double[] array) {
021                double theSum = 0;
022                for (double d : array) {
023                        theSum += d;
024                }
025                return theSum/array.length;
026        }
027
028        public static void main (String[] args) {
029                double[] a = { 2, 6, -5, 9, 8, -1, 0 };
030                StdOut.println (Arrays.toString (a));
031                StdOut.format ("min=%f, max=%f, mean=%f\n", min(a),  max(a),  mean(a) );
032        }
033}