The following program defines an array of four integers, wires in integers via an array initializer, computes the sum of the integers, and displays the average:
public class Demonstrate { public static void main (String argv[]) { int sum = 0; int durations [] = {65, 87, 72, 75}; for (int counter = 0; counter < durations.length; ++counter) { sum = sum + durations[counter]; } System.out.print("The average of the " + durations.length); System.out.println(" durations is " + sum / durations.length); } } --- Result --- The average of the 4 durations is 74