Java Unary Operator Examples


The unary operator works on a single operand. Following are the examples of unary operators supported in java. Assume A = 60 and B = 20.

OperatorDescriptionExample
~ (bitwise compliment)
Binary One's Complement Operator is unary and has the effect of 'flipping' bits.
(~A ) will give -61 which is 1100 0011 in 2's complement form due to a signed binary number.
++ (Increment)
Increases the value of operand by 1.
B++ gives 21
-- (Decrement)
Decreases the value of operand by 1.
B-- gives 19

Updated on: 30-Jul-2019

407 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements