File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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)
Reply locked New topic


Shivaprasad P Kanaganahallimath
Ranch Hand

Joined: Sep 25, 2006
Posts: 48
public static void main(String [] args){
int i=9;
int j=i;
System.out.println("i value is:"+i+"ff"+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;
int p=i++;
int j=p;
System.out.println("i value is:"+i+"ff"+j);

i value is:11 j value is:10

could you guys explain this please.

Shiva Prasad P.K.
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
A lot of disscussions was there on this topic search for them in the forum.
Any way for the time being just consider the value of i has been assigned before its increment there is no effect in the value of i.

~Sanjeev Singh<br />SCJP 1.5
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Closing needless duplicate. And yes, this is one of the most asked questions in this forum, so please search the forum first before posting.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
I agree. Here's the link:
subject: i=i++;
It's not a secret anymore!