manohar143
Programmer
public class test
{
public static void main(String args[])
{
int a=2;
System.out.println("a"+a);
a=a++;
System.out.println("a"+a);
a=++a;
System.out.println("a"+a);
}
}
Result of this program is
a 2
a 2
a 3
How come the value of a is not changed after the statement a=a++;
I know that first it will assign the value and then increment. But in next statement i am trying to print the value of a still 2 . As far as i know after assigning the value of a is 2 then post increment process is done. So where the value of a is stored that time.
{
public static void main(String args[])
{
int a=2;
System.out.println("a"+a);
a=a++;
System.out.println("a"+a);
a=++a;
System.out.println("a"+a);
}
}
Result of this program is
a 2
a 2
a 3
How come the value of a is not changed after the statement a=a++;
I know that first it will assign the value and then increment. But in next statement i am trying to print the value of a still 2 . As far as i know after assigning the value of a is 2 then post increment process is done. So where the value of a is stored that time.