Recall & Review
beginner
What is a unary operator in Java?
A unary operator is an operator that works with only one operand to perform an operation, such as incrementing a value or negating a number.
Click to reveal answer
beginner
What does the ++ operator do when placed before a variable (e.g., ++x)?
It increments the variable by 1 before using its value in an expression.
Click to reveal answer
intermediate
What is the difference between ++x and x++ in Java?
++x increments the value first, then uses it; x++ uses the current value first, then increments it.
Click to reveal answer
beginner
What does the unary minus operator (-) do to a number?
It changes the sign of the number, turning positive numbers into negative and vice versa.
Click to reveal answer
beginner
What is the effect of the logical complement operator (!) in Java?
It reverses the boolean value: true becomes false, and false becomes true.
Click to reveal answer
What does the expression ++x do in Java?
✗ Incorrect
The ++ before x means increment first, then use the value.
What is the result of applying the unary minus operator to 5 (i.e., -5)?
✗ Incorrect
Unary minus changes the sign, so 5 becomes -5.
Which operator reverses a boolean value in Java?
✗ Incorrect
The ! operator flips true to false and false to true.
What does x-- do in Java?
✗ Incorrect
The -- after x means use the value first, then decrement.
Which of these is NOT a unary operator in Java?
✗ Incorrect
+= is a compound assignment operator, not unary.
Explain the difference between prefix (++x) and postfix (x++) increment operators in Java.
Think about when the value changes relative to its use.
You got /3 concepts.
Describe how unary operators can change the value or state of a variable with examples.
Consider numbers and booleans separately.
You got /4 concepts.