It's not a secret anymore!*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 41029
    
  43
+1 for the subject.


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

Joined: Aug 16, 2005
Posts: 14074
    
  16

To summarize it with code:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37879
    
  22
This question arises frequently. We have an FAQ about it.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ++
 
Similar Threads
Strange system.out
ResultSet problem
carriage return
Wanted: Minimal Web Server Example
Plz help, code is provided.