Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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.
 
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!