aspose file tools*
The moose likes Java in General and the fly likes problem with increment operator. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "problem with increment operator." Watch "problem with increment operator." New topic
Author

problem with increment operator.

viki Bhardwaj
Ranch Hand

Joined: Nov 07, 2011
Posts: 74

hi Guys,

here i have a question regarding increment operator , code is bellow


in the above code i'm trying to increment the value of x , at the first sop(x) is good ,but at x=x++ here is also ok because here is the post increment so it first assign the value and then increment ..here my
doubt is that...
when i print through sop(x) then it again print 11 as output but what happened with corresponding post incremented value of x which should be 12 logically..but sopln() is unable to get it why???
so please i would like to know about this ....how ??

hopefully, waiting for your reply.

regards:
vivek
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

Vivek Bhardwaj wrote:when i print through sop(x) then it again print 11 as output but what happened with corresponding post incremented value of x which should be 12 logically..but sopln() is unable to get it why???

It got lost. You need to go back to:
x = x++;
What do you think that does?

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

We also have an article on this : PostIncrementOperatorAndAssignment
viki Bhardwaj
Ranch Hand

Joined: Nov 07, 2011
Posts: 74

Seetharaman Venkatasamy wrote:We also have an article on this : PostIncrementOperatorAndAssignment



Thanks! Seetharaman for sharing the valuable link ,...it was good enough explanation.
 
wood burning stoves
 
subject: problem with increment operator.