Solve it... public class test {public static void main(String[] args) { int i=5; i=i++; System.out.println("result::"+i); }}The result wil be 5..!! and not 6 why???
Dear Friend, this is post increment, that is first assign the value and then increment.so in this case you first assign the value, so i become 5, now you increment which is of no use.that's why the answer is 5;But rather assigning a value if you directly write i++, then the value become 6;
It is same as System.out.println(i++);public class test{public static void main(String[] args) { int i=5; System.out.println("result::"+i++); }}It prints 5 first then increments.