• Post Reply Bookmark Topic Watch Topic
  • New Topic

Head First Java Chapt 4 Mixed Messages" question.  RSS feed

 
Lisa Austin
Ranch Hand
Posts: 178
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This looks like a puzzle which has stumped a few people in the past here on the forums. I looked at other people questions and the answers but I'm not sure if it helped me. I am trying to work the problem but I'm confused as to how certain pieces of the code works in general. This is page 90 of the Head First Java Book, second edition. I have a few questions to verify how things work so I hope I can communicate my questions correctly. I appreciate any help. Thank You!

Here is the full puzzle code:





Here are the specific lines I'm having problems with. These are lines 10 and 12 from above.

and



I'm currently working through the problem with pencil and paper and this is what I have this for the first loop.



For line # 11
is " m4a[x].counter" an array reference variable assigned the value of 1 ( counter being 0 at the time) ?
Would I read it as m4a[0].counter = 1?

For line #13
Is the variable "count" now assigned the value 1 plus it calls the maybeNew method?
Does it pass the argument "0" into the "maybeNew" method's parameter and then the "maybeNew" method returns 1?
If I'm correct on any of this would I then read this as count = 1+1?


 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For that sort of puzzle you will have to get a pencil and paper and go through the execution of the program.

Also search this forum for mixed messages because there is a good chance you will find somebody else has had the same question. Actually, you will probably find this old thread useful.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!