public class Increment {
public static void main(String[] args) {
int a = 10;
System.out.println(a++);
System.out.println(a);
/*
System.out.println(++a);
*/
}
}
This is a simple program based on relatively simple concept and simple operation. Post increment means incrementing afterwards and pre increment means incrementing before. As in the ouput below you can see the program first prints value 10 that was initially assigned to it and then after 11. The reason why 11 was not printed on the first output display is that post increment takes one step further so that it will print the incremented value in the next step.
In the pre increment operation, 1 is added before printing the value of the variable. So it prints the value 11.