Decrement & Increment Operator In Java
Java Decrement Operator ?
Decrement operators are used to decrement the value of the variable by one. The decrement operator -- subtracts 1 to its operand,
// decrement operator
➦Both increment and decrement operator are used on single operand or variable, so it is called as unary operator.
➦ Unary operators are having higher priority than the other operators it means unary operators are execute before other operators
Java Increment and Decrement Operators
Example 1: Decrement Operator
Before x--: Value of x = 10 y = 20 After x--: Value of x = 9
Example 2: Pre Decrement Operator:
Before --x: Value of x = 10 y = 19 After --x: Value of x = 9
Java Increment Operator ?
Increment operators are used to increase the value of the variable by one. The increment operator ++ adds 1 to its operand,
// increment operator
Example 1: Increment Operator:
Example 2: Increment Operator:
Before x++: Value of x = 10 y = 20 After x++: Value of x = 11
Example 2: Pre Increment Operator:
Before ++x: Value of x = 10 y = 21 After ++x: Value of x = 11