Java Unary Operator Examples

Java Programming Java8Object Oriented ProgrammingJava Technologies

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
raja
Published on 08-Feb-2018 07:04:49
Advertisements