← Unit 4 · all exercises
Saved in this browser only

Average of an array

Return the average of the numbers as a decimal. An empty array averages 0.0. Dividing two ints throws away the fraction, so one side needs to be a double.

double average(int[] values)

Solution.java
Loading editor…
Results

Examples

  • Solution.average(new int[]{1, 2, 3}) → 2
  • Solution.average(new int[]{1, 2}) → 1.5

There are also 3 hidden tests you can't see. Solve the problem, not the examples.