Decrement Operator Example Java Program

Definition

Operators are used to manipulate primitive data types. Java operators can be classified as unary, binary, or ternary?meaning taking one, two, or three arguments, respectively. Decrement operator helps to subtract 1 from a variable.

Syntax

Variable_name--;

Decrement Operator Example Program

class DecrementOperatorDemo{
	public static void main(String args[]){
	int i = 5, j = 5, sum = 0;
	System.out.println("Value of i is " + i + ", j is " + j+ " and sum is " + sum);
	sum = i + j--;
	System.out.println("Value of i is " + i + ", j is " + j +" and sum is " + sum);
	}
}

Sample Output

Output is:
Value of i is 5, j is 5 and sum is 0
Value of i is 5, j is 4 and sum is 10