• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

hi corey i read ur tips doubt

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic