• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

can anyone please explain why these codes work?  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Posts: 61777
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

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.
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!