Java Array Average avg(byte[] values)

Here you can find the source of avg(byte[] values)

Description

The average of an array

License

Open Source License

Parameter

Parameter Description
values the array of values to average

Return

the average of the array

Declaration

public static final float avg(byte[] values) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /** The average of an array
     * @param values the array of values to average
     * @return the average of the array//from ww  w  .  j  a v a  2  s  .  c  o m
     */
    public static final float avg(byte[] values) {
        return avg(values, 0, values.length);
    }

    /** The average of a subset of an array
     * @param values the array of values to average
     * @param offset the offset into the array at which to start averaging values
     * @param length the number of values to average from the array
     * @return the average of the array subset specified
     */
    public static final float avg(byte[] values, int offset, int length) {
        int total = 0;
        int offLen = offset + length;
        for (int i = offset; i < offLen; i++) {
            total += values[i];
        }
        return total / (float) length;
    }

    /** The average of an array
     * @param values the array of values to average
     * @return the average of the array
     */
    public static final float avg(short[] values) {
        return avg(values, 0, values.length);
    }

    /** The average of a subset of an array
     * @param values the array of values to average
     * @param offset the offset into the array at which to start averaging values
     * @param length the number of values to average from the array
     * @return the average of the array subset specified
     */
    public static final float avg(short[] values, int offset, int length) {
        int total = 0;
        int offLen = offset + length;
        for (int i = offset; i < offLen; i++) {
            total += values[i];
        }
        return total / (float) length;
    }

    /** The average of an array
     * @param values the array of values to average
     * @return the average of the array
     */
    public static final float avg(char[] values) {
        return avg(values, 0, values.length);
    }

    /** The average of a subset of an array
     * @param values the array of values to average
     * @param offset the offset into the array at which to start averaging values
     * @param length the number of values to average from the array
     * @return the average of the array subset specified
     */
    public static final float avg(char[] values, int offset, int length) {
        int total = 0;
        int offLen = offset + length;
        for (int i = offset; i < offLen; i++) {
            total += values[i];
        }
        return total / (float) length;
    }

    /** The average of an array
     * @param values the array of values to average
     * @return the average of the array
     */
    public static final float avg(int[] values) {
        return avg(values, 0, values.length);
    }

    /** The average of a subset of an array
     * @param values the array of values to average
     * @param offset the offset into the array at which to start averaging values
     * @param length the number of values to average from the array
     * @return the average of the array subset specified
     */
    public static final float avg(int[] values, int offset, int length) {
        int total = 0;
        int offLen = offset + length;
        for (int i = offset; i < offLen; i++) {
            total += values[i];
        }
        return total / (float) length;
    }

    /** The average of an array
     * @param values the array of values to average
     * @return the average of the array
     */
    public static final double avg(long[] values) {
        return avg(values, 0, values.length);
    }

    /** The average of a subset of an array
     * @param values the array of values to average
     * @param offset the offset into the array at which to start averaging values
     * @param length the number of values to average from the array
     * @return the average of the array subset specified
     */
    public static final double avg(long[] values, int offset, int length) {
        long total = 0;
        int offLen = offset + length;
        for (int i = offset; i < offLen; i++) {
            total += values[i];
        }
        return total / (double) length;
    }

    /** The average of an array
     * @param values the array of values to average
     * @return the average of the array
     */
    public static final float avg(float[] values) {
        return avg(values, 0, values.length);
    }

    /** The average of a subset of an array
     * @param values the array of values to average
     * @param offset the offset into the array at which to start averaging values
     * @param length the number of values to average from the array
     * @return the average of the array subset specified
     */
    public static final float avg(float[] values, int offset, int length) {
        float total = 0;
        int offLen = offset + length;
        for (int i = offset; i < offLen; i++) {
            total += values[i];
        }
        return total / (float) length;
    }

    /** The average of an array
     * @param values the array of values to average
     * @return the average of the array
     */
    public static final double avg(double[] values) {
        return avg(values, 0, values.length);
    }

    /** The average of a subset of an array
     * @param values the array of values to average
     * @param offset the offset into the array at which to start averaging values
     * @param length the number of values to average from the array
     * @return the average of the array subset specified
     */
    public static final double avg(double[] values, int offset, int length) {
        double total = 0;
        int offLen = offset + length;
        for (int i = offset; i < offLen; i++) {
            total += values[i];
        }
        return total / (double) length;
    }
}

Related

  1. averageChroma(float[] chromaSums, int countChromas)
  2. averageLuminance(double[] luminance)
  3. averageNonZeros(int[] array)
  4. averagePt(double[][] ndPoints)
  5. averageX(long[][] intImg, int width, int height, int i, int j, int dl, int dr)
  6. avg(double a, double b)
  7. avg(double v1, double v2)
  8. avg(double values[], int size, boolean ignoreNan)
  9. avg(double... a)