File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Flaw in Program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Flaw in Program" Watch "Flaw in Program" New topic
Author

Flaw in Program

Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218
I've just started introducing myself to the Head First Java book. On page 14 there is a program as follows:



In the book it states that there is a flaw in the program but I can't see where it is as the output to screen I get is (which starts from 99 but I can't copy that far up from DOS screen):

6 bottles of beer on the wall
6 bottles of beer on the wall
6 bottlesof beer.
Take one down.
Pass it around.
5 bottles of beer on the wall
5 bottles of beer on the wall
5 bottlesof beer.
Take one down.
Pass it around.
4 bottles of beer on the wall
4 bottles of beer on the wall
4 bottlesof beer.
Take one down.
Pass it around.
3 bottles of beer on the wall
3 bottles of beer on the wall
3 bottlesof beer.
Take one down.
Pass it around.
2 bottles of beer on the wall
2 bottles of beer on the wall
2 bottlesof beer.
Take one down.
Pass it around.
1 bottles of beer on the wall
1 bottle of beer on the wall
1 bottleof beer.
Take one down.
Pass it around.
No more bottles of been on the wall

C:\Java>

Can anyone highlight what the flaw is?
Dani Atrei
Ranch Hand

Joined: Feb 17, 2004
Posts: 73
1 bottles of beer on the wall


The output isn't perfect, I think that's all

Dan


Si altas son las torres, el valor es alto - Alberti
Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218
Ah! Because a while loop has been used it will go through it once and use the singular bottle. The if statement should of been outside the while loop then.

Thank you!
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Maureen Charlton:
Ah! Because a while loop has been used it will go through it once and use the singular bottle. The if statement should of been outside the while loop then.

Thank you!


I don't think that will fix the problem, either. But you should try it and see what happens.

Layne


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Flaw in Program