Adding up every element in an array is another pattern you will write repeatedly. You start a running total at and add each element:
int[] values = {10, 20, 30, 40, 50};
int sum = 0;
for (int val : values) {
sum += val;
}
System.out.println(sum); // 150
The for-each loop works well here because you do not need the index. You only need each value.
To get the average, divide the sum by the array's length. Watch out for integer division. If both sum and length are int, Java truncates the result. Cast one of them to double first:
double avg = (double) sum / values.length;