Here you can find the source of avg(byte[] values)
Parameter | Description |
---|---|
values | the array of values to average |
public static final float avg(byte[] values)
//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; } }