Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic