Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Master your knowledge of Java programming with our immersive quiz based on 'Thinking in Java'. Test your skills with detailed questions and receive hints and explanations to enhance your learning. Get ready to ace your Java exam!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


What does the unary minus operator do?

  1. Negates a boolean

  2. Inverts the sign of the data

  3. Increments the value

  4. Nothing

The correct answer is: Inverts the sign of the data

The unary minus operator, represented by the "-" symbol, changes the sign of the data it is applied to. It does this by multiplying the value by -1. This operation is commonly used in algebra to simplify equations and in programming to manipulate numerical values. The other options, such as A Negates a boolean and C: Increments the value, do not accurately describe the purpose of the unary minus operator. Option A refers to the logical "not" operation, which is not related to this question. Option C refers to the increment operator, which increases the value by 1, not changing its sign. Option D states that the operator does nothing, which is incorrect as it does have a defined purpose.