Returns the maximum value of some list of doubles. - Java java.lang

Java examples for java.lang:double Array

Description

Returns the maximum value of some list of doubles.

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        double vals = 2.45678;
        System.out.println(max(vals));
    }/*  w  ww  .j a  va  2 s .  co  m*/

    /**
     * Returns the maximum value of some list of doubles.
     * @param vals
     * @return
     */
    public static final double max(double... vals) {
        double max = Double.MIN_VALUE;

        for (double v : vals)
            if (v > max)
                max = v;

        return max;
    }
}

Related Tutorials