//Author: A really cool guy. public class VarargsTest { public static double average (double... arr) { double sum = 0; for(int x = 0; x < arr.length; x++) { sum = sum + arr[x]; } return sum / arr.length; } public static void main(String[] args) { System.out.println(average(2,4,6,8)); System.out.println(average(12,64,123,41,26,198)); System.out.println(average()); //allowed, although this will output } //NaN as it will be dividing by zero }