15 / 30
Live
Code challenge
Easy
Warm-up: fix the semicolon so "positive" is guarded and "done" always prints
Description
The starter below contains the rogue-semicolon bug from the pitfall slide. The stray ; at the end of the if header closes the if with an empty body, so the println for "positive" runs unconditionally. Fix the method so that "positive" prints only when x is greater than 0, and "done" prints on its own line for every call.
You may assume that x is any int value. Do not change the main method. Writing the braces around the if body is the habit the pitfall slide is pushing toward.
Examples
Example 1
Input
5
Expected output
positive done
Example 2
Input
-2
Expected output
done
Example 3
Input
0
Expected output
done
You have not submitted yet. Edit the code, then tap Run to check
it against the instructor's tests.
1 / 3
Java · OpenJDK 13