← Unit 2 · all exercises
Saved in this browser only

Positive, negative or zero

Return 1 when the number is positive, -1 when it is negative, and 0 when it is zero.

int sign(int n)

Solution.java
Loading editor…
Results

Examples

  • sign(7) → 1
  • sign(-7) → -1

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