Suggest you put a "System.out.println("************");" at the end of each verse/stanza, as the second line in the "if (beerNum > 0)" block. Then you will have ************ separating verses which makes it easier to read.campbell@campbell-laptop:~/java$ java BeerSong
99 bottles of beer on the wall
99 bottles of beer
Take one down.
Pass it around.
98 bottles of beer on the wall
98 bottles of beer on the wall
98 bottles of beer
Take one down.
Pass it around.
and it appears that if you comment out the System.out.println shown, you get rid of the repeated line.
. . . using what I copied and pasted from Besjamain Greenaway's 2nd post, plus the ********** line.campbell@campbell-laptop:~$ cd java
campbell@campbell-laptop:~/java$ java BeerSong
9 bottles of beer on the wall
9 bottles of beer
Take one down.
Pass it around.
8 bottles of beer on the wall
************
8 bottles of beer on the wall
8 bottles of beer
Take one down.
Pass it around.
7 bottles of beer on the wall
************
7 bottles of beer on the wall . . .
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Does it work?Sven Brocking wrote:So this is the right solution? . . . cheers
Campbell Ritchie wrote:Welcome to the Ranch
![]()
You have a test about whether beerNum > 0 inside a while (beerNum > 0) loop. It is much neater to move the "no more bottles" line outside the loop, then you don't need that test any more. You are duplicating a test with the change from "bottles" to "bottle", but that probably still fits better inside the loop.
By the way: your indentation is inconsistent. Sometimes you have { at the end of the line and sometimes on a line to itself. I prefer the line to itself convention, but that is a preference not a requirement. You should however be consistent about which convention you follow.
99 bottles of beer on the wall
99 bottles of beer
take one down
pass it around
98 bottles of beer on the wall
98 bottles of beer on the wall
Paulo Couto wrote:Here is my attempt to the same book exercise
Paulo Couto wrote:
today is my first day learning Java. I don't have any programming experience so bear with me please.
There's also a pluralization issue when you get to one bottle of beer, and "0 bottle of beer on the wall" shouldn't be there. But that's quite nit-picky.
Paulo Couto wrote:
P.S - Sorry for my poor english.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |