Win a copy of Murach's MySQL this week in the JDBC and Relational Databases 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Head First Java 2nd Edition - Page 118, chapter 5

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, i'm going through an exercise called be the jvm.

However, the output that I am supposed to get is completely different to the way i have worked it out.

I reach y being 15, and my x is 8.

But the output should show 13 15 x = 6;

Here is the code:



could someone walk through the code with me, and show me where I am exactly going wrong?

Thank you for your help!
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

john pep wrote:Here is the code:
...
could someone walk through the code with me, and show me where I am exactly going wrong?


Sure; but first, get the indenting right. I don't know if your original source was like it (sometimes books do it on purpose to make the logic more difficult to follow). You can edit your post with the 'Edit' button, and I suspect just doing that may give you a better idea what's going on.

Oh, and use spaces to indent; not TABs.

Winston
 
Marshal
Posts: 79010
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It showed 13 15 x = 6 for me.
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:It showed 13 15 x = 6 for me.



...me too
 
Campbell Ritchie
Marshal
Posts: 79010
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had to resort to some desperate measures, like remembering where I put my copy of HFJ. At least you appear to have copied the code correctly. You are not consistent about the end comments, however. I know a lot of people here don't like end comments, but if you are going to use them at all, they should follow every }.

What you have to do is to go into the loops and write down the values of x and y. Let's try:-...etc, etc
If you get to the print instructions, be careful to work out whether you print the old value of y or the new value.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:It showed 13 15 x = 6 for me.


and me too(13 15 x=6)
and in P122 you can see this answer too
 
Well THAT's new! Comfort me, reliable tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic