← Unit 1 · all exercises
Saved in this browser only

Round to the nearest whole number

Return the value rounded to the nearest whole number. 9.6 becomes 10 and 9.4 becomes 9. Math.round gives you a long, so you will need a cast.

int nearest(double value)

Solution.java
Loading editor…
Results

Examples

  • nearest(9.6) → 10
  • nearest(9.4) → 9

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