This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Ranch Office 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


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » This Site » Ranch Office
Bookmark "Post- Increment for a variable" Watch "Post- Increment for a variable" New topic
Author

Post- Increment for a variable

M.Sanjay
Greenhorn

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;
i=i++;
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,
M.Sanjay.
Ajith Kallambella
Sheriff

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.
Thanks!


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

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)
forum.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Post- Increment for a variable
 
It's not a secret anymore!