• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

increment operation-weird result

 
Jenny raj
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class test
{
public static void main(String args[])
{
int i=5;
for(int j=0;j<10;j++)
{
i=i++;
System.out.println(i);

}
}
}


output :
5
5
5
5
5
5
5
5
5
5



why the output is not 6,7,8....15

plz explain
 
Henry Wong
author
Marshal
Pie
Posts: 21446
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This exact issue is actually discussed in the JavaRanch FAQ.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic