File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
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: 7063
    
  16

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?
Artlicles 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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with increment operator.
 
Similar Threads
Static variable question
Java small code confusion
Dissecting the post-fix operator
K&B Book for Scjp 6 - Chapter 5 question 8 doubt
doubts getting exponentially INCREMENTed