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

Please Explain

 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System.out.println("i j");
int i=2;
long j=2L;
for (i++, j=(long)0; j<3; System.out.println(""+i +" "+j++));

Please explain
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Judging by the looks of it, it appears to be a fragment of Java code.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what's the deal ??
output is
3 0
3 1
3 2
which is perfectly normal
the initialization part is
i++, j=(long)0
i's value is now 3 and j's 0
the condition part is j<3 which means that the loop will iterate three times (j=0,j=1,j=2)
the update part is
System.out.println(""+i +" "+j++)
which prints i's and j's values, the value of i is always 3 and the value of j is increment from 0 to 2...
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
reply
    Bookmark Topic Watch Topic
  • New Topic