Two Laptop Bag*
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
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.
 
 
subject: Post- Increment for a variable
 
Similar Threads
Dout with this key word
how can v pass javascript values to jsp
Arrays
Methods
Polymorphism Problem