Java Increment Operators

Java Increment Operators


Increment Operator In Java
Increment operator in Java is a unary operator.
Increment operator, and its types with examples are defined as below -
Increment operator is of two types - 
Post increment- In post-increment ++ comes after the value like a++, or num++. In this operator, the value is firstly used and then increment.
Pre increment - In this operator ++ comes before the value like ++a, ++b, and the value is first increased and then used.
Now we will see an example which uses both post-increment, and pre-increment operators - 
The following program demonstrates the increment operator.
// Demonstrate ++.

class IncDec {
public static void main(String args[]) {
int a = 1;
int b = 2;
int c;
int d;
c = ++b;
d = a++;
c++;
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);
System.out.println("d = " + d);
}
}


 
Output - 
a = 2
b = 3
c = 4
d = 1