This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Head First Object Exercise Chapter Two Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First Object Exercise Chapter Two" Watch "Head First Object Exercise Chapter Two" New topic
Author

Head First Object Exercise Chapter Two

Richard Chambers
Ranch Hand

Joined: Apr 03, 2008
Posts: 40
OK, I'm back. I took a Java course this spring at the local college, and learned enough to know I don't know what I'm doing. I'm now starting Head First Java with a study buddy. We're in Chapter Two - Objects, It's one of those complete the code from a list of "snippet" things. We chose different codes, yet have the same output. Neither of us can explain why we chose the differing snippets other than we worked it through our heads and this one worked. Can someone explain which of the coding is preferred and why? or does it matter and both are right.

Thanks

My Coding



His Coding



BTW -- My coding agrees with the book, so I assume his is wrong, but I can't show him why.

Thanks again
[ September 17, 2008: Message edited by: Richard Chambers ]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19672
    
  18

The exercise was to fill in some gaps and get the code to print 10 right?
Then if both of you have used available code snippets, you are both right.

It just happens sometimes - there is not one correct answer, but multiple.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Add some println statements, and you will see the different behavior...



"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First Object Exercise Chapter Two