public class Head1 {
public static void main(String[] args) {
int beerNum = 99;
String word = "bottles";
while (beerNum > 0) {
if (beerNum == 1) {
word = "bottle";
}
System.out.println(beerNum + " " + word + " of beer on the wall");
System.out.println(beerNum + " " + word + " of beer");
System.out.println("Take one down.");
System.out.println("Pass it around.");
beerNum = beerNum - 1;
if (beerNum > 0) {
System.out.println(beerNum + " " + word + " of beer on the wall");
}
if (beerNum == 1) {
System.out.println(beerNum + " " + word + " of beer on the wall");
} else {
System.out.println("No more bottles of beer on the wall!");
}
}
}
}
This example code from a Java book prints out the song from 99 bottles to no bottles of beer on the wall. The problem is that when it is 1 bottle of beer on the wall, it still says bottles. I tried to fix this by adding if (beerNum == 1) section at the end. But still, it shows 1 bottles of beer on the wall, i bottle of beer on the wall.
I don't know what to change to fix this. Do I create another while section?
If you can give em a hint so I can solve it on my own that would be cool too! Because I do understand that I the actual song output is in the first if section, but I don't know where I should edit "if" or if i should just create another if section.
Thanks!