public class apples {
public static void main(String[] args) {
int beerNum = 99;
String word = "bottles";
while (beerNum > 0) {
if (beerNum == 1) {
word = "bottle"; // ONE bottle
}
System.out.println(beerNum + " " + word + " of beer on the wall, " + beerNum + " " + word + " of beer");
beerNum = beerNum - 1;
if (beerNum > 0) {
System.out.println("Take one down, pass it round " + beerNum + " " + word + " of beer");
}
}
if (beerNum == 0) {
System.out.println("No more bottles of beer");
}
}
}
The output is:
99 bottles of beer on the wall, 99 bottles of beer
Take one down, pass it round 98 bottles of beer
98 bottles of beer on the wall, 98 bottles of beer
Take one down, pass it round 97 bottles of beer
97 bottles of beer on the wall, 97 bottles of beer
Take one down, pass it round 96 bottles of beer
96 bottles of beer on the wall, 96 bottles of beer
Take one down, pass it round 95 bottles of beer
95 bottles of beer on the wall, 95 bottles of beer...
(And so on and so forth)
3 bottles of beer on the wall, 3 bottles of beer
Take one down, pass it round 2 bottles of beer
2 bottles of beer on the wall, 2 bottles of beer
Take one down, pass it round 1 bottles of beer
1 bottle of beer on the wall, 1 bottle of beer
No more bottles of beer
Why isn't the String word equalling "bottle"? Instead it says "bottles" in "Take one down, pass it round 1 BOTTLES of beer.
Also after "1 bottle of beer on the wall, 1 bottle of beer" it doesn't say "Take one down pass it round"
word,beerNumis not equal1, but when you outputTake one down, pass it round 1 bottles of beer,beerNumis1, but you've already decided what thewordshould be...beerNumis down to a value of2.