Created
October 26, 2011 18:46
-
-
Save mahmoudhossam/1317350 to your computer and use it in GitHub Desktop.
A failed attempt at 99 bottles of beer in Java.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Bottles { | |
public static void main (String args[]) { | |
String lyrics = "%1$d bottles of beer on the wall, %1$d bottles" + | |
" of beer.\nTake one down and pass it around, %2$d bottles of" + | |
" beer on the wall.\n"; | |
String lyricsTwo = "%1$d bottle of beer on the wall, %1$d bottle" + | |
" of beer.\nTake one down and pass it around, %s bottles of beer" + | |
" on the wall.\n"; | |
String lyricsOne = "%1$d bottle of beer on the wall, %1$d bottle" + | |
" of beer.\nTake one down and pass it around, no more bottles of" + | |
" beer on the wall.\n"; | |
String lyricsZero = "No more bottles of beer on the wall, no more" + | |
" bottles of beer.\nGo to the store and buy some more, 99" + | |
" bottles of beer on the wall."; | |
for(int i = 99; i >= 0; i--){ | |
if(i == 2){ | |
System.out.printf(lyricsTwo, i, "no"); | |
} | |
else if(i == 1){ | |
System.out.printf(lyricsOne, i); | |
} | |
else if(i == 0){ | |
System.out.println(lyricsZero); | |
return; | |
} | |
System.out.printf(lyrics, i, i-1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment