1public class JavaExample {
2
3 public static void main(String[] args) {
4 double[] arr = {19, 12.89, 16.5, 200, 13.7};
5 double total = 0;
6
7 for(int i=0; i<arr.length; i++){
8 total = total + arr[i];
9 }
10
11
12 /* arr.length returns the number of elements
13 * present in the array
14 */
15 double average = total / arr.length;
16
17 /* This is used for displaying the formatted output
18 * if you give %.4f then the output would have 4 digits
19 * after decimal point.
20 */
21 System.out.format("The average is: %.3f", average);
22 }
23}