Last Updated: June 7, 2026
Every integer is positive, negative, or zero. Report which one n is.
Zero is its own case. Asking "is n greater than 0?" and "is n less than 0?" leaves the case where both are false, which is when n is zero. Structure the checks so each runs only when the previous ones did not match, and the last branch absorbs whatever is left.
0 returns "Zero".n fits in 32 bits → A plain int holds the value with no overflow risk, and the comparisons are exact.An else-if ladder picks one outcome from a small set of mutually exclusive options. Each test runs only when the earlier ones failed, and the final else is a catch-all.
Ask whether n is greater than 0. If not, ask whether it is less than 0. If neither holds, the value can only be zero, so the final branch returns "Zero" without another comparison.
n is greater than 0, return "Positive".n is less than 0, return "Negative"."Zero".Input:
The first test asks whether 0 is greater than 0, which is false. The second test asks whether 0 is less than 0, which is also false. With both comparisons ruled out, control reaches the final branch, and the answer is "Zero".