集册 Java实例教程 获取数组中的最大值。

获取数组中的最大值。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

440
获取数组中的最大值。

/**
 from
* 时代Java公众号 - nowjava.com 
**/

//package com.nowjava;


public class Main {

    /**

     * Gets the maximum value in the array.

     * @param input

     * @return

     */

    public static short max(short[] input) {

        short max = Short.MIN_VALUE;

        for (int i = 0; i < input.length; i++) {

            if (input[i] > max) {

                max = input[i];

            }

        }

        return max;

    }/* from n o w    j a v a  . c o m*/


    /**

     * Gets the maximum value in the array.

     * @param input

     * @return

     */

    public static double max(double[] input) {

        double max = -Double.MAX_VALUE;

        for (
展开阅读全文