aspose file tools*
The moose likes Java in General and the fly likes ++ 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 "++" Watch "++" New topic
Author

++

Miran Cvenkel
Ranch Hand

Joined: Nov 23, 2010
Posts: 147
out of curiosity:



I get out 0, but then again i have no idea how that work at all.
Next:

gives me 1.

I would expect 1 in first case.

as it looks now:

would give same thing at start, but the code is different.



Any thought about that ?


Searchable nature photo gallery: http://agrozoo.net/jsp/Galery.jsp?l2=en
Stuart James
Greenhorn

Joined: Nov 23, 2010
Posts: 4
If I am understanding your question correctly, the first call to out.Print gives 0 because you have used the postfix increment operator - the value of c is printed, then incremented.

If you want to see 1 in the first call you need to use the prefix increment operator (++c). Then the value is incremented prior to printing.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
+1 for the subject.


Ping & DNS - my free Android networking tools app
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14270
    
  21

To summarize it with code:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39415
    
  28
This question arises frequently. We have an FAQ about it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ++