• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

99 Bottles of Beer

 
loni gashi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm new here and also new in java. I'm reading Head First Java second edition and
arrived at exercise 99 Bootes of beer. I wrote this code but the output isn't correct. Can anyone explain
to me why isn't working as expected ( x doesn't take value 100 and then degrease by 1 , but it take value 0 and then decreases)

 
Greg Charles
Sheriff
Posts: 2989
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Loni, and welcome to JavaRanch!

It's a good idea to tell us what's not working to your expectations. It's explained in our FAQ under: TellTheDetails ⇐ (Click here). In this case, I think I can guess that the numbers are going down faster than you want them to. Is that right? You are subtracting from x too often. Just once in the loop is enough.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A similar question has already been asked here so you might find some useful information there.
 
loni gashi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for quick replies.
I realized that i made an stupid mistake, The command should have been inside while brackets
Kemal Sokolovic I saw that post but I tried to make it shorter and achive the same result. Now it is working as it should.
Thanks again.

 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've notices that your solution is slightly different from that one, but I posted a link as a guideline you might use.

1 bottles of beer on the wall, 1 bottles of beer.
Take one down and pass it around, 0 bottles of beer on the wall.

This is the output of your program. The last line differs a little from the one I know about.
 
Joel Christophel
Ranch Hand
Posts: 250
1
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I remember this from a while back: http://www.coderanch.com/t/409007/java/java/Head-Beersong
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic