Unary operator in java
There are many types of operators in java :
- Arithmetic operator
- Unary operator
- Relational operator
- Logical operator
- Assignment operator
- Ternary operator
- Bitwise operator
Unary Operator :
Unary operator is used with a operand . or only one operand or variable is used.
Unary operator is also divided in two types :
- Increment operator
- Decrement operator
Increment operator : Increment operator is used to increment the value by 1.or in increment operator the value of operand is increased by 1.
Types of increment operator :
a .pre-increment
b. post increment
b. post-increment : In this the value of operand is used first then the value is increased by 1.
b. post-decrement
a. pre-increment : In this the value of operand is firstly increased by 1 then we use the value.
Syntax: + + operand ;
example : + + a ; If the value of a is 5 , first value of a is increased by 1 means 6 . Then we use the value of a in operation .
Syntax : operand + +;
example : a + +; If the value of a is 5 , first it uses the value of a then the value is increased by 1.
Decrement operator : decrement operator is used to decrement the value by 1.
Type of decrement operator:
a. pre-decrementb. post-decrement
a. pre-decrement : It first decrease the value then use the value.
Syntax : - - operand; example : - -a ; if the value of a is 5 ,first it decrease the value by 1 means 4 , then use the value .
b. post-decrement : It first uses the value of operand then decrease the value by one.
Syntax: operand - -; example : a - -; first it uses the value then the value is decreased by 1 .
Tags:
PROGRAMMING