Java Increment Operator

Java Increment operator takes single operand as input and increments the value of operand by 1..

++ symbol is used for Increment Operator.

Syntax – Increment Operator

Following is the syntax for Increment Operator.

++operand
//or
operand++

The first form of increment is called pre-increment. The value of the operand in returned and then the increment happens.

The first form of increment is called post-increment. The value of the operand is incremented and then the value is returned.

The operand could be of any numeric datatype.

ADVERTISEMENT

Example 1 – Increment Integer

In the following example, we shall take an integer and increment its value by one using Increment operator.

Java Program

public class IncrementExample {
	public static void main(String[] args) {
		int a = 7;
		a++;
		System.out.print(a);
	}
}

Output

8

Let us use pre-increment form, and increment the value.

Java Program

public class IncrementExample {
	public static void main(String[] args) {
		int a = 7;
		System.out.println(++a);
		System.out.print(a);
	}
}

Output

8
8

Example 2 – Increment Floating Point Value

In the following program, we shall increment a float.

Java Program

public class IncrementExample {
	public static void main(String[] args) {
		float a = 7.2f;
		a++;
		System.out.print(a);
	}
}

Output

8.2

Conclusion

In this Java Tutorial, we learned how to use Java Increment Operator.