Skip to content

Instantly share code, notes, and snippets.

@danahern
Created November 11, 2008 10:13
Show Gist options
  • Save danahern/23795 to your computer and use it in GitHub Desktop.
Save danahern/23795 to your computer and use it in GitHub Desktop.
public class BeerSong {
public static void main (String[]args){
int beerNum = 99;
String word = "bottles";
while (beerNum > 0){
if (beerNum == 1){
word = "bottle"; // singular, as in ONE 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 == 1){
System.out.println(beerNum + " bottle of beer on the wall");
} else if (beerNum > 0) {
System.out.println(beerNum + " " + word + " of beer on the wall");
} else {
System.out.println("No more bottles of beer on the wall.");
}//end else
}//end while loop
}//end main method
}//end class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment