Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Can anyone explain this behaviour in detail.?

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Trickytest {
public static void main ( String args [ ] ) {
int i = 10 ; // line 1
i = ++i ; // line 2
System.out.println("After 1st increment: "+i);
i = i++ ;
System.out.println("After 2nd increment: "+i);
i=i++;
System.out.println("After 3rd increment: "+i);
i=i++;
System.out.println("After 4th increment: "+i);
i=i++;
System.out.println("After 5th increment: "+i);

System.out.println ("value of "+ i ); // line 4
}
}

This prints value of i 11 each time ,i know i++ first assigns value and then increment i & ++i first assign and then increment i.But i need explanation because if i use j=i++;it prints incremented value..
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try removing "i=i++" to "i++" only
 
Mahesh Gurav
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got the explanation ,you can see it at..
web page
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic