/**
* Simple program that prints out the words
* to the 99 Bottles of Beer on the Wall
* song.
*
* Based on the BeerSong example in the
* _Head_First_Java_ book with corrections.
*/
public class BeerSong {
public static void main (String[] args) {
int beerNum = 99;
String word = "bottles";
while (beerNum > 0) {
System.out.println(beerNum + " " + word + " of beer on the wall.");
System.out.println(beerNum + " " + word + " of beer.");
if (beerNum == 1) {
System.out.println("Take it down.");
word = "bottle";
} else {
System.out.println("Take one down.");
}
System.out.println("Pass it around.");
beerNum--;
if (beerNum == 1) {
word = "bottle";
}
if (beerNum > 0) {
System.out.println(beerNum + " " + word + " of beer on the wall.\n");
} else {
System.out.println("No more bottles of beer on the wall.");
}
}
}
}
/**
* Simple program that prints out the words
* to the 99 Bottles of Beer on the Wall
* song.
*
* Based on the BeerSong example in the
* _Head_First_Java_ book with corrections.
*/
public class BeerSong {
public static void main(String[] args) {
int beerNum = 99;
String word = “bottles”;
while (beerNum > 0) {
System.out.println(beerNum + ” ” + word + ” of beer on the wall.”);
System.out.println(beerNum + ” ” + word + ” of beer.”);
if (beerNum != 1) {
System.out.println(”Take one down.”);
}
else {
System.out.println(”Take it down.”);
}
System.out.println(”Pass it around.”);
beerNum–;
switch (beerNum) {
case 0:
System.out.println(”No more bottles of beer on the wall.”);
break;
case 1:
word = “bottle”;
// yes, there is no break;
default:
System.out.println(beerNum + ” ” + word + ” of beer on the wall.\n”);
break;
}
}
}
}
Comment by Nek Strebor — April 7, 2008 @ 12:24 pm