Win a copy of Pragmatic AI this week in the Artificial Intelligence 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!