I was going through the Head First java book and stumbled on this exercise which gave me an output as a-b c-d and asked to put together the broken pieces of codes. I tried to write my own first without looking at the given codes and somehow came up with these:
The codes do not really make sense to me but it generates the same output as given. Also, the broken pieces of codes after put together (or what i think they are) are:
And those do not really make sense to me either. Can anyone please help?
I added code tags to your post (always use the tags), which make your code look so much better but the second code block shows what happens if you omit indentation
Please tell us the page number in HFJ, and whether this is some sort of puzzle. There are always multiple ways to solve computing problems, but the puzzles in HFJ make you solve them using only certain bits of code. I think you will understand the flow of control better if you write down the values of all your variables on paper and follow the execution with a pencil. Show us what you have; I don't have the time to go through all that code now.
Also consider searching this forum. HFJ is a popular book, and many peope have solved that puzzle, so maybe there will be a discussion of that selfsame problem.