← Unit 2 · all exercises
Saved in this browser only

Never below zero

Return the value, except that anything below zero becomes zero. This is what stops a health bar going negative.

int clamp(int value)

Solution.java
Loading editor…
Results

Examples

  • clamp(5) → 5
  • clamp(-5) → 0

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