aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes variables 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "variables" Watch "variables" New topic
Author

variables

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hai,
i want why the output is different in java for the below code
---
int a=2;
a=a++;
System.out.println(a);
---
the output is 2
why
&how the code is executed(i want some algor)
thank u
srinivasan.e

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
It's because the expression
a++
is evaluated after the assignment.
a is assigned a and then a is increased by 1.
Instead use only the statement a++ or a=++a instead.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: variables