Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to read this?

 
sal lazar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Can anyone explain to me why the following code below returns 14 1?

 
vinayak jog
Ranch Hand
Posts: 83
MySQL Database Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ranch
count gets number 9 from the main method
and gets 5 from the maybeNew method

so sums to 14
and counter is one per object and you are accessing it from the last object its only 1

read carefully the code you ll get it ..... have nice time


 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vinayak jog, please read this:
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
which is from the contents page for the "Beginning Java" forum. We usually delete such direct answers, but yours is quite vague, so I shall keep it here.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sal lazar, welcome to the Ranch

Always tell us where the exercise is from; is that example from Head First Java™? Which page? Please be consistent with indentation and use spaces, not tabs, for indenting.

I think you will have to do it the hard way, with a pencil and paper., writing down the values of x, count and counter at each iteration through the loop. alternatively, yo ucan add a line to the loop which prints out those values, something like:If you are using m4a[x].counter, that line would have to go after your line 9. You can work out similar lines for other parts of the program. Then you can follow the flow of control and the values used. then yo ucan see where the 9 and 5 and 1 come from.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic