Skip to main content

Practice · 5 of 5

Three cases, one method

CHALLENGE
Difficulty: intermediate+25 XP

Implement int clamp(int value, int lo, int hi): below lo → lo, above hi → hi, otherwise value. Assume lo <= hi. The spec enumerates the cases; your job is to enumerate them in the right ORDER so no case is shadowed.

Back to lesson: Practice: Specification workshop