Java Array Max Value max(double[] values)

Here you can find the source of max(double[] values)

Description

Calculates the maximum over an given array of doubles.

License

Open Source License

Parameter

Parameter Description
values double array the maximum is calculated from

Return

maximum value of the given double array

Declaration

public static double max(double[] values) 

Method Source Code

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

public class Main {
    /**//from  w ww.j  a  v  a  2s  .c om
     * Calculates the maximum over an given array of doubles.
     * 
     * @param values
     *            double array the maximum is calculated from
     * @return maximum value of the given double array
     */
    public static double max(double[] values) {
        try {
            double max = values[0];
            for (double v : values) {
                if (v > max)
                    max = v;
            }
            return max;
        } catch (ArrayIndexOutOfBoundsException e) {
            return 0;
        }
    }

    /**
     * Calculates the maximum over an given array of integers.
     * 
     * @param values
     *            integer array the maximum is calculated from
     * @return maximum value of the given integer array
     */
    public static int max(int[] values) {
        try {
            int max = values[0];
            for (int v : values) {
                if (v > max)
                    max = v;
            }
            return max;
        } catch (ArrayIndexOutOfBoundsException e) {
            return 0;
        }
    }

    /**
     * Calculates the maximum over an given array of longs.
     * 
     * @param values
     *            long array the maximum is calculated from
     * @return maximum value of the given long array
     */
    public static long max(long[] values) {
        try {
            long max = values[0];
            for (long v : values) {
                if (v > max)
                    max = v;
            }
            return max;
        } catch (ArrayIndexOutOfBoundsException e) {
            return 0;
        }
    }
}

Related

  1. max(double[] matrix)
  2. max(double[] series)
  3. max(double[] vals)
  4. max(double[] values)
  5. max(double[] values)
  6. max(double[] x)
  7. max(final double aval, double[] b, final int bi, final int len)
  8. max(final double... doubles)
  9. max(final double[] array)