← Unit 1 · all exercises
Saved in this browser only

Average of two whole numbers

Return the average of two whole numbers as a decimal. The average of 3 and 4 is 3.5, not 3 — dividing two ints throws the half away, so one side has to become a double first.

double average(int a, int b)

Solution.java
Loading editor…
Results

Examples

  • average(3, 4) → 3.5
  • average(10, 20) → 15

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