This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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++;
Similar Threads
String label?
Compilation problem with if condition
why i=i++; doesn't get incremented