Bookmark Topic Watch Topic
  • New Topic

i=i++;

 
Shivaprasad P Kanaganahallimath
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Report post to moderator
public static void main(String [] args){
int i=9;
i=++i;
i=i++;
int j=i;
System.out.println("i value is:"+i+"ff"+j);
...
the output is
i value is:10 j value is:10
---------------------------------------------------------------------------

but the following gives different answer
public static void main(String [] args){
int i=9;
i=++i;
int p=i++;
int j=p;
System.out.println("i value is:"+i+"ff"+j);

i value is:11 j value is:10


could you guys explain this please.
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Report post to moderator
A lot of disscussions was there on this topic search for them in the forum.
Any way for the time being just consider the value of i has been assigned before its increment there is no effect in the value of i.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Report post to moderator
Closing needless duplicate. And yes, this is one of the most asked questions in this forum, so please search the forum first before posting.
 
    Bookmark Topic Watch Topic
  • New Topic