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

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

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

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.