0
0
Javaprogramming~5 mins

Unary operators in Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AIncrements x by 1, then returns the new value
BReturns x, then increments it by 1
CDecrements x by 1, then returns the new value
DReturns x without changing it
What is the result of applying the unary minus operator to 5 (i.e., -5)?
AError
B5
C0
D-5
Which operator reverses a boolean value in Java?
A++
B!
C--
D~
What does x-- do in Java?
AIncrements x by 1, then returns the new value
BDecrements x by 1, then returns the new value
CReturns x, then decrements it by 1
DReturns x without changing it
Which of these is NOT a unary operator in Java?
A+=
B--
C!
D++
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.