jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Post- Increment for a variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Post- Increment for a variable" Watch "Post- Increment for a variable" New topic

Post- Increment for a variable


Joined: Jun 29, 2001
Posts: 5
Respeted Sir/Madam,
We have a doubt in the following code:-
class Sample
public static void main(String args[])
int i=10;
System.out.println("The value of i is: " + i);
When I run the program,it is giving the output as 10.
Why so?If I store the result in another variable,it is taking as 11.What is the difference between both the cases?
Thanking you,
Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
Your name 'sanjaykumaresan' does not comply with the JavaRanch naming policy. Please spare a moment and re-register with a name that meets the requirements. We will take care of deleting your current login.

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
Please use the JavaRanch forum for discussing site-related issues only. I moving this discussion to Java in General(beginner)
rani bedi
Ranch Hand

Joined: Feb 06, 2001
Posts: 358
Do a search in the forum. This question has been discussed earlier.

Cheers,<br />Rani<br />SCJP, SCWCD, SCBCD
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
The value held in the variable is the value BEFORE the post-increment. The value AFTER the post-increment is being help in "working memory" elsewhere.

"JavaRanch, where the deer and the Certified play" - David O'Meara
Tim Anderson

Joined: Jun 29, 2001
Posts: 6
this will do what you want:
I agree. Here's the link: http://aspose.com/file-tools
subject: Post- Increment for a variable
It's not a secret anymore!