Java Array Min Value minValue(float[] arr)

Here you can find the source of minValue(float[] arr)

Description

Returns the smallest value in the array

License

Open Source License

Parameter

Parameter Description
arr array of floats

Return

the value

Declaration

public static float minValue(float[] arr) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from  w  ww. ja v  a 2s. c o m*/
     * Returns the smallest value in the array
     * 
     * @param arr array of floats
     * @return the value
     */
    public static float minValue(float[] arr) {
        if (arr.length < 0)
            return 0;

        float min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] < min) {
                min = arr[i];
            }
        }

        return min;
    }

    /**
     * Returns the smallest value in the array
     * 
     * @param arr array of doubles
     * @return the value
     */
    public static double minValue(double[] arr) {
        if (arr.length < 0)
            return 0;

        double min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] < min) {
                min = arr[i];
            }
        }

        return min;
    }

    /**
     * Returns the smallest value in the array
     * 
     * @param arr array of bytes
     * @return the value
     */
    public static byte minValue(byte[] arr) {
        if (arr.length < 0)
            return 0;

        byte min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] < min) {
                min = arr[i];
            }
        }

        return min;
    }

    /**
     * Returns the smallest value in the array
     * 
     * @param arr array of shorts
     * @return the value
     */
    public static short minValue(short[] arr) {
        if (arr.length < 0)
            return 0;

        short min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] < min) {
                min = arr[i];
            }
        }

        return min;
    }

    /**
     * Returns the smallest value in the array
     * 
     * @param arr array of ints
     * @return the value
     */
    public static int minValue(int[] arr) {
        if (arr.length < 0)
            return 0;

        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] < min) {
                min = arr[i];
            }
        }

        return min;
    }

    /**
     * Returns the smallest value in the array
     * 
     * @param arr array of longs
     * @return the value
     */
    public static long minValue(long[] arr) {
        if (arr.length < 0)
            return 0;

        long min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] < min) {
                min = arr[i];
            }
        }

        return min;
    }
}

Related

  1. minValue(double array[][])
  2. minValue(double[] from)
  3. minValue(double[] values)
  4. minValue(double[] values)
  5. minValue(final int[] arr)
  6. minValue(int[] array)
  7. minValue(int[] values)
  8. minValue(long[] array)
  9. minX(final float[] vertices)