get Max from double array - Java Collection Framework

Java examples for Collection Framework:Array Algorithm

Description

get Max from double array

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        double[] array = new double[] { 34.45, 35.45, 36.67, 37.78,
                37.0000, 37.1234, 67.2344, 68.34534, 69.87700 };
        System.out.println(getMax(array));
    }/*from w w  w .ja v a  2 s  . c om*/

    public static double getMax(double[] array) {
        double max = 0;
        for (int i = 0; i < array.length; i++) {
            if (array[i] > max) {
                max = array[i];
            }
        }
        return max;
    }
}

Related Tutorials