• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • 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: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It showed 13 15 x = 6 for me.
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:It showed 13 15 x = 6 for me.


...me too
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!