Language Basics Java Book

public class Main {
public static void main(String[] args) {
int[] intArray = new int[] { 1, 2, 3, 4, 5 };
// calculate sum
int sum = 0;
for (int i = 0; i < intArray.length; i++){
sum = sum + intArray[i];
}
// calculate average
double average = sum / intArray.length;
System.out.println("average: " + average);
}
}

The output:
average: 3.0