Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

VM bag ?

Thread view: 
vahan - 21 May 2007 15:41 GMT
What does it print in out ? And why?

public class Simple {
   static int i =2;

   public static void main(String[] args){
     i = (++i) / (++i);
     System.out.println("   " +  i);

   }
Chris Dollin - 21 May 2007 15:47 GMT
> What does it print in out ? And why?
>
[quoted text clipped - 6 lines]
>
>     }

I smell homework.

Signature

Is it a bird? It is a plane? No, it's:   http://hpl.hp.com/conferences/juc2007/
WARNING.  Various parts of this product may be more than one billion years old.

Hewlett-Packard Limited                                          registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN          690597 England

Lew - 21 May 2007 15:57 GMT
> What does it print in out ? And why?
>
[quoted text clipped - 6 lines]
>
>     }

For the first question, compile and run the program and you will find out.

You could also read the Java Language Specification (JLS) for that
information, and it will tell you why.

<http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html>

Hint: Order of evaluation.
<http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.7>

As far as the prefix and postfix increment operators go:
<http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.14.2>
<http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.15.1>

From the tutorials:
<http://java.sun.com/docs/books/tutorial/java/nutsandbolts/op1.html>
<http://java.sun.com/docs/books/tutorial/java/nutsandbolts/expressions.html>

Learn to use the Sun website for tutorials and specifications.

Signature

Lew

vahan - 22 May 2007 06:28 GMT
> > What does it print in out ? And why?
>
[quoted text clipped - 29 lines]
> --
> Lew

Any way, many thanks to all
Andrew Thompson - 22 May 2007 07:38 GMT
>> > What does it print in out ? And why?

(snip many links from Lew)
...
>...many thanks to all

Please don't forget to report back your conclusions
after reading the links given by Lew.  I could guess
what it would print by eyeballing the code, but the
*explanation* was in the links.

Signature

Andrew Thompson
http://www.athompson.info/andrew/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.