Java Number Range Create range(double[] vals)

Here you can find the source of range(double[] vals)

Description

Get the range of an array.

License

Open Source License

Declaration

public static double[] range(double[] vals) 

Method Source Code

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

public class Main {
    /**//from   w  ww.java2s.  c o m
     * Get the range of an array.
     * will return null if the array is empty.
     * Will return a double[2] (min at 0, max at 1).
     */
    public static double[] range(double[] vals) {
        if (vals.length == 0) {
            return null;
        }

        double[] rtn = { vals[0], vals[0] };

        for (int i = 1; i < vals.length; i++) {
            if (rtn[0] > vals[i]) {
                rtn[0] = vals[i];
            } else if (rtn[1] < vals[i]) {
                rtn[1] = vals[i];
            }
        }

        return rtn;
    }
}

Related

  1. range(double a, double b, double step)
  2. range(double value1, double value2)
  3. range(double[] data, int to, int stride, int numElementsEachStride)
  4. range(double[] min, double[] max, double[] min2, double[] max2)
  5. range(final int max)
  6. range(float number, float value, float range)
  7. range(int begin, int end)
  8. range(int end)