Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

hi corey i read ur tips doubt  RSS feed

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class Test
{
public static void main(String[] args)
{
int i = 0;
i = i++;
System.out.println(i);
}
}
//suppose if i use for loop instead of this incrementor then waht is the ouput of i?

for(int i=0;i<n;i++)//here after first loop it should become 1 write is //correct or not
System.out.println(i);
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm...I'm not entirely sure I understand your question.

The trick used with the post-increment (or post-decrement) operator is to use it with an assignment, such as this:

i = i++;

This causes the increment to be "overwritten" by the assignment. If you simply use the post-increment operator without an assignment, like this:

i++;

You get just what you'd expect, i to be incremented by 1.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!