Java Array Max Value max(int... array)

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

Description

max

License

Open Source License

Declaration

public static int max(int... array) 

Method Source Code

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

public class Main {
    public static int max(int... array) {
        if (array.length == 0)
            throw new ArrayIndexOutOfBoundsException();

        int max = Integer.MAX_VALUE;

        for (int i : array) {
            if (i > max)
                max = i;/*  w  w  w  .ja  v  a 2  s .  c om*/
        }

        return max;
    }

    public static long max(long... array) {
        if (array.length == 0)
            throw new ArrayIndexOutOfBoundsException();

        long max = Long.MAX_VALUE;

        for (long l : array) {
            if (l > max)
                max = l;
        }

        return max;
    }

    public static float max(float... array) {
        if (array.length == 0)
            throw new ArrayIndexOutOfBoundsException();

        float max = Float.MAX_VALUE;

        for (float f : array) {
            if (f > max)
                max = f;
        }

        return max;
    }

    public static double max(double... array) {
        if (array.length == 0)
            throw new ArrayIndexOutOfBoundsException();

        double max = Double.MAX_VALUE;

        for (double d : array) {
            if (d > max)
                max = d;
        }

        return max;
    }
}

Related

  1. max(float[] v1, float[] v2)
  2. max(int array[])
  3. max(int value1, int value2, int... values)
  4. max(int... _is)
  5. max(int... args)
  6. max(int... list)
  7. max(int... values)
  8. max(int... values)
  9. max(int... values)