Java Array Max Value max(double[] array)

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

Description

Computes the max of the given array.

License

Apache License

Parameter

Parameter Description
array the array

Return

the max

Declaration

public static double max(double[] array) 

Method Source Code

//package com.java2s;
/**/*from  w w  w .  j av a  2s.  co m*/
 * 
 *    Copyright 2017 Florian Erhard
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * 
 */

public class Main {
    public static int max(int[] a) {
        int re = Integer.MIN_VALUE;
        for (int i : a)
            re = Math.max(re, i);
        return re;
    }

    public static int max(int[] a, int start, int end) {
        int re = Integer.MIN_VALUE;
        for (int i = start; i < end; i++)
            re = Math.max(re, a[i]);
        return re;
    }

    public static long max(long[] a, int start, int end) {
        long re = Long.MIN_VALUE;
        for (int i = start; i < end; i++)
            re = Math.max(re, a[i]);
        return re;
    }

    public static double max(double[] a, int start, int end) {
        double re = Double.NEGATIVE_INFINITY;
        for (int i = start; i < end; i++)
            re = Math.max(re, a[i]);
        return re;
    }

    public static int max(int[][] m) {
        int re = Integer.MIN_VALUE;
        for (int[] a : m)
            for (int i : a)
                re = Math.max(re, i);
        return re;
    }

    public static float max(float[] a) {
        float re = a[0];
        for (float i : a)
            re = Math.max(re, i);
        return re;
    }

    /**
     * Computes the max of the given array.
     * @param array the array
     * @return the max
     */
    public static double max(double[] array) {
        if (array.length == 0)
            return Double.NEGATIVE_INFINITY;
        double re = array[0];
        for (int i = 1; i < array.length; i++)
            re = Math.max(re, array[i]);
        return re;
    }
}

Related

  1. max(double[] array)
  2. max(double[] array)
  3. max(double[] array)
  4. max(double[] array)
  5. max(double[] array)
  6. max(double[] data)
  7. max(double[] data)
  8. max(double[] list)
  9. max(double[] matrix)