File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes i=i++; Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "i=i++;" Watch "i=i++;" New topic
Author

i=i++;

Shivaprasad P Kanaganahallimath
Ranch Hand

Joined: Sep 25, 2006
Posts: 48
public static void main(String [] args){
int i=9;
i=++i;
i=i++;
int j=i;
System.out.println("i value is:"+i+"j value is:"+j);
...
the output is
i value is:10 j value is:10
---------------------------------------------------------------------------

but the following gives different answer
public static void main(String [] args){
int i=9;
i=++i;
int p=i++;
int j=p;
System.out.println("i value is:"+i+"j value is:"+j);

i value is:11 j value is:10


could you guys explain this please.


Shiva Prasad P.K.
Costa lamona
Ranch Hand

Joined: Sep 24, 2006
Posts: 102
Hi

that is because "prefix and postfix" ++, does not differ from each other until the identifier is involved in expression, for instance

produce output 1
but

produce output 0
and

produce output 1


SCJP 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: i=i++;