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

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

Description

max

License

Apache License

Declaration

public static int max(int... values) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static int max(int... values) {
        if (values.length < 2) {
            return values[0];
        }/*from  w ww .  j  ava 2  s . c o  m*/

        int result = Math.max(values[0], values[1]);
        for (int i = 2; i < values.length; i++) {
            result = Math.max(result, values[i]);
        }

        return result;
    }

    public static long max(long... values) {
        if (values.length < 2) {
            return values[0];
        }

        long result = Math.max(values[0], values[1]);
        for (int i = 2; i < values.length; i++) {
            result = Math.max(result, values[i]);
        }

        return result;
    }

    public static float max(float... values) {
        if (values.length < 2) {
            return values[0];
        }

        float result = Math.max(values[0], values[1]);
        for (int i = 2; i < values.length; i++) {
            result = Math.max(result, values[i]);
        }

        return result;
    }

    public static double max(double... values) {
        if (values.length < 2) {
            return values[0];
        }

        double result = Math.max(values[0], values[1]);
        for (int i = 2; i < values.length; i++) {
            result = Math.max(result, values[i]);
        }

        return result;
    }
}

Related

  1. max(int... args)
  2. max(int... array)
  3. max(int... list)
  4. max(int... values)
  5. max(int... values)
  6. max(int... values)
  7. max(int... xs)
  8. max(int[] a)
  9. max(int[] a)