BASIC CONCEPT ON INCREMENT ON JAVA

leoumesh(72)
Published in
GEMS
Words
99
Reading
1 min
Listen
Play
6y
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.

Screenshot_4.png

In the pre increment operation, 1 is added before printing the value of the variable. So it prints the value 11.

Screenshot_2.png

BASIC CONCEPT ON INCREMENT ON JAVA | Ecency