Java Array Min Value minMaxAvg(int[] arr)

Here you can find the source of minMaxAvg(int[] arr)

Description

min Max Avg

License

Open Source License

Declaration

public static int[] minMaxAvg(int[] arr) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {

    public static int[] minMaxAvg(int[] arr) {
        int minIndex = 0;
        int minValue = arr[0];
        int maxIndex = 0;
        int maxValue = arr[0];
        int total = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (minValue > arr[i]) {
                minIndex = i;// ww w.  ja  v a  2 s.  co  m
                minValue = arr[i];
            }
            if (maxValue < arr[i]) {
                maxIndex = i;
                maxValue = arr[i];
            }
            total += arr[i];
        }
        return new int[] { minValue, minIndex, maxValue, maxIndex, total / arr.length };
    }
}

Related

  1. minMax(float... values)
  2. minMax(float[] array)
  3. minmax(int[] values)
  4. minMax(int[] values)
  5. minmax(String args[], boolean minimum)
  6. minMaxOverArraySubset(double[] array, Iterable subset, boolean min)
  7. minNonNeg(int... vals)
  8. minNum(Number iArr[])
  9. minOf(double[] da, double val)