Java Array Max Value maxDistance(byte[] array, int maxDistance)

Here you can find the source of maxDistance(byte[] array, int maxDistance)

Description

Returns true when the max distance between values in the array is NOT larger then the given value

License

Open Source License

Parameter

Parameter Description
array a parameter
maxDistance a parameter

Declaration

public static boolean maxDistance(byte[] array, int maxDistance) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  w  w w. j a va  2  s . c  o  m
     * Returns true when the max distance between values in the array is NOT larger then the given value
     * @param array
     * @param maxDistance
     * @return
     */
    public static boolean maxDistance(byte[] array, int maxDistance) {

        if (array == null || array.length == 0) {
            return true;
        }

        int min = array[0];
        int max = array[0];
        for (byte value : array) {
            min = Math.min(value, min);
            max = Math.max(value, max);
            if (Math.abs(min - max) > maxDistance) {
                return false;
            }
        }
        return true;
    }

    public static double max(double[] array) {

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

    public static float max(float[] array) {

        float max = Float.NEGATIVE_INFINITY;
        for (int i = 0; i < array.length; i++) {
            if (array[i] > max) {
                max = array[i];
            }
        }
        return max;
    }
}

Related

  1. maxcount(int[] vals, int max, int maxcount)
  2. maxDblArrayValue(int npts, double[] dbls)
  3. maxdex(float... values)
  4. maxdiffbits(int initoffset, int[] i, int pos, int length)
  5. maxDiffLocation(double[] list1, double[] list2)
  6. maxDouble(double a, double... others)
  7. maxElement(double[] d)
  8. maxElement(int[] array)
  9. maxElementIndex(final double[] array)