集册 Java实例教程 计算短类型数组中的最大绝对值。

计算短类型数组中的最大绝对值。

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

415
计算短型数组中的最大绝对值。
//时 代 J a v a 公 众 号 - nowjava.com 提 供


//package com.nowjava;


public class Main {

    /**

     * Calculates max absolute value.

     * @param input

     * @return

     */

    public static short maxValue(short[] input) {

        short max = Short.MIN_VALUE;

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

            if (Math.abs(input[i]) > max) {

                max = (short) Math.abs(input[i]);

            }

        }

        return max;

    }


    /**

     * Calculates max absolute value.

     * @param input

     * @return

     */

    public static double maxValue(double[] input) {

        double max = Double.MIN_VALUE;

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

            if (
展开阅读全文