Here you can find the source of avg(int[] xs)
public static double avg(int[] xs)
//package com.java2s; //License from project: Open Source License public class Main { public static double avg(int[] xs) { if (xs.length == 0) return 0.0; else//from w w w.java 2 s. co m return ((double) sum(xs)) / xs.length; } public static double avg(double[] xs) { if (xs.length == 0) return 0.0; else return sum(xs) / xs.length; } public static int sum(int[] xs) { int result = 0; for (int x : xs) result += x; return result; } public static double sum(double[] xs) { double result = 0.0; for (double x : xs) result += x; return result; } }