99 bottles of beer: Difference between revisions
Content added Content deleted
(New page: {{puzzle}}In this puzzle, print out the entire "99 bottles of beer on the wall" song. For those who do not know the song, the lyrics follow this form: X bottles of beer on the wall X bot...) |
(Added Java, needed to spearate the verses in BASIC version) |
||
Line 20:
PRINT "Take one down, pass it around"
PRINT x-1; "bottles of beer on the wall"
PRINT
NEXT x</qbasic>
Line 30 ⟶ 31:
}
}</c>
=={{header|Java}}==
<java>public class Beer{
public static void main(String[] args){
for(int x = 99;x>=1; --x)
System.out.println(x+"bottles of beer on the wall\n"+x+"bottles of beer\n"+"Take one down, pass it around\n"+(x-1)+"bottles of beer on the wall\n");
}
}</java>
|
Revision as of 19:19, 28 February 2008
99 bottles of beer is a programming puzzle. It lays out a problem which Rosetta Code users are encouraged to solve, using languages and techniques they know. Multiple approaches are not discouraged, so long as the puzzle guidelines are followed. For other Puzzles, see Category:Puzzles.
In this puzzle, print out the entire "99 bottles of beer on the wall" song. For those who do not know the song, the lyrics follow this form:
X bottles of beer on the wall X bottles of beer Take one down, pass it around X-1 bottles of beer on the wall X-1 bottles of beer on the wall ... Take one down, pass it around 0 bottles of beer on the wall
Where X and X-1 are replaced by numbers of course. Grammatical support for "1 bottle of beer" is optional. As with any puzzle, try to do it in as creative/concise/comical a way as possible (simple, obvious solutions allowed, too).
See also: http://99-bottles-of-beer.net/
BASIC
<qbasic>FOR x = 99 TO 1 STEP -1
PRINT x; "bottles of beer on the wall" PRINT x; "bottles of beer" PRINT "Take one down, pass it around" PRINT x-1; "bottles of beer on the wall" PRINT
NEXT x</qbasic>
C++
<c>#include<stdio> using namespace std; int main(int argc, char* argv[]){
for(int x = 99;x>=1; --x){ cout<<x<<"bottles of beer on the wall\n"<<x<<"bottles of beer\n"<<"Take one down, pass it around\n"<<x-1<<"bottles of beer on the wall\n\n"; }
}</c>
Java
<java>public class Beer{
public static void main(String[] args){ for(int x = 99;x>=1; --x) System.out.println(x+"bottles of beer on the wall\n"+x+"bottles of beer\n"+"Take one down, pass it around\n"+(x-1)+"bottles of beer on the wall\n"); }
}</java>