Calculates max absolute value in short type array. - Java Collection Framework

Java examples for Collection Framework:Array Algorithm

Description

Calculates max absolute value in short type array.

Demo Code


//package com.java2s;

public class Main {
    /**//from  w ww .j av a  2s  .  c o  m
     * 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 (Math.abs(input[i]) > max) {
                max = Math.abs(input[i]);
            }
        }
        return max;
    }
}

Related Tutorials