Java Array Max Value max(final int... numbers)

Here you can find the source of max(final int... numbers)

Description

max

License

Open Source License

Return

the largest of the given numbers

Declaration

public static int max(final int... numbers) 

Method Source Code

//package com.java2s;
/*//from  w ww .j a  v  a2s  . co m
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2007-2008, Open Source Geospatial Foundation (OSGeo)
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */

public class Main {
    /**
     * @return the largest of the given numbers
     */
    public static int max(final int... numbers) {
        if (numbers.length == 0) {
            throw new IllegalArgumentException("at least one parameter is required");
        }

        int max = numbers[0];
        for (int i = 1; i < numbers.length; i++) {
            int number = numbers[i];
            if (number > max) {
                max = number;
            }
        }

        return max;
    }
}

Related

  1. max(final double[] values)
  2. max(final double[] vec)
  3. max(final float[] a, final float[] b)
  4. max(final int... array)
  5. max(final int... integers)
  6. max(final int... values)
  7. max(final int[] arr)
  8. max(final int[] result, final int[] vec1, final int[] vec2)
  9. max(final int[] values)