← Unit 4 · all exercises
Saved in this browser only

Average of a list

Return the average of the numbers as a decimal. An empty list averages 0.0.

double average(java.util.ArrayList<Integer> list)

Solution.java
Loading editor…
Results

Examples

  • Solution.average(new java.util.ArrayList<>(java.util.List.of(1, 2, 3))) → 2
  • Solution.average(new java.util.ArrayList<>(java.util.List.of(1, 2))) → 1.5

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