Here you can find the source of avg(int[] arr)
Parameter | Description |
---|---|
arr | the array to be AVG |
public static float avg(int[] arr)
//package com.java2s; //License from project: Open Source License public class Main { public static float avg(int[] arr) { return (float) sum(arr) / arr.length; }//from ww w . jav a 2s .c o m public static float avg(double[] arr) { return (float) sum(arr) / arr.length; } public static float avg(float[] arr) { return (float) sum(arr) / arr.length; } public static float avg(long[] arr) { return (float) sum(arr) / arr.length; } public static float avg(short[] arr) { return (float) sum(arr) / arr.length; } public static float avg(byte[] arr) { return (float) sum(arr) / arr.length; } public static int sum(int[] arr) { int sum = 0; for (int i = 0, l = arr.length; i < l; i++) { sum += arr[i]; } return sum; } public static double sum(double[] arr) { double sum = 0; for (int i = 0, l = arr.length; i < l; i++) { sum += arr[i]; } return sum; } public static float sum(float[] arr) { float sum = 0; for (int i = 0, l = arr.length; i < l; i++) { sum += arr[i]; } return sum; } public static long sum(long[] arr) { long sum = 0; for (int i = 0, l = arr.length; i < l; i++) { sum += arr[i]; } return sum; } public static short sum(short[] arr) { short sum = 0; for (int i = 0, l = arr.length; i < l; i++) { sum += arr[i]; } return sum; } public static byte sum(byte[] arr) { byte sum = 0; for (int i = 0, l = arr.length; i < l; i++) { sum += arr[i]; } return sum; } }