public class Sample
{
public static void main(String[] args) throws Exception
{
//part 1
int i=1;
i=i++;
i=++i;
i=i++;
System.out.println(i);
//part 2
i=1;
int a=i++;
a=++i;
a=i++;
System.out.println(a+"
"+i);
}
}
Output
2
3
4
Yesterday my friend asked this question. I little bit confused about this. part 1 prints the i value as 2. Post increment is not working here. But in the part 2, it works. I can understand the part 2 but i have confused in part 1. How actually it works? Can anybody make me understand?
See Question&Answers more detail:os