The java operator taking one operand is called Increment and Decrement Operators(Unary Operator) .
The most basic two unary operators such as increment operator(++) and decrement operator(--).
Again increment operator is divided into two categories such as pre-increment and post-increment.
Similarly decrement operator is also devided into pre-decrement and post-decrement.
In case of pre-increment/ decrement first the value of variable will increment / decrement a value by 1, then it will display.
where as in case of post-increment / decrement, first the value of variable will display then it will increment / decrement.
+ // Unary plus operator; indicates positive value (numbers are positive without this, however)
- //Unary minus operator; negates an expression
++ //Increment operator; increments a value by 1
-- //Decrement operator; decrements a value by 1
! //Logical complement operator; inverts the value of a Boolean
let's see some following small examples :
class Increment { public static void main(String args[]) { int x=5,y; y=x++ + x++ + ++x + x++ + ++x; System.out.println("y="+y); } }
Output
y=37
class TestUnary { public static void main(String args[]) { int x=8,y; y=++x + ++x - x++ + ++x - --x; System.out.println("y="+y); } }
Output
y=10
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc