Forums Register Login

Just need a little help.

+Pie Number of slices to send: Send

= 25 1

So this is one of programs in head first java...i want to know HOW the answer became 25 1...in detail if anybody could help me out, im trying to understand it the best i can, i only see code here though i cant really see HOW the answer became 25 1, step by step..please clarify for me please.
Thank you very much!
+Pie Number of slices to send: Send
Never be afraid to put some System.out.println statements in the code to see what is going on. If "count" is something you want to understand how it is changing, put some statements in just before and after each place where count can be changed, and print its value before and after.
+Pie Number of slices to send: Send
Well, the output is final value of the local variable count (25) and the final value of the counter field of one instance of Mix4 (1).

count starts at 0
there is a loop that iterates twenty times
each time through the loop, count is incremented by 1
each time through the loop, count is additionally incremented by the result of the maybeNew() method
maybeNew() returns 0 or 1. Everything else it does has no meaning whatsoever.
maybeNew() will be called with the values 0, 1, 2, ..., 19, but returns 1 only for 0, 1, 2, 3, 4, i.e. five times
so count gets incremented by 20 by hitting line 10 twenty times
and count gets incremented by 5 more by the five times maybeNew() returns 1
that makes count 25.

I'll let you work out the second part.
+Pie Number of slices to send: Send
I cannot figure out the second part...maybe I should restart the book?
lol
+Pie Number of slices to send: Send
Start by searching this forum. You will find other threads about the same question, for example this one. Go through that and see whether it gives you any useful information.
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 991 times.
Similar Threads
how exactly does this code compile?
Java Problem = List of errors, Clueless. HELP
Help me to understand this code
code
Anyone could explain this script to me?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:30:31.