Java :: Aufgabe #43
6 Lösungen

99 Bottles of Beer - Selbstständige Lösung
Anfänger - Java
von pocki
- 11.01.2013 um 14:07 Uhr
Programmiere eine eigenständige Lösung zur gängigen Programmier-Übung bzw. Lied 99 Bottles of Beer
Ausgabe:
Ausgabe:
Konsolenausgabe:
99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 99 bottles of beer on the wall.
98 bottles of beer on the wall, 98 bottles of beer.
... usw.
Lösungen:

class a{ public static void main(String[]a){ int i=99; String s=" of beer on the wall",o="no more",b=" bottle"; while(i>-1){ System.out.println((i>0?i:"No more")+b+(i==1?"":"s")+s+", "+(i>0?i:o)+b+(i==1?"":"s")+" of beer.\n"+(i-->0?"Take one down and pass it around, ":"Go to the store and buy some more, ")+(i<0?"99":(i>0?i:o))+b+(i==1?"":"s")+s+".\n"); } } }

public class bottles { public static void main(String[] args) { int n=99; do { if(n==0) { System.out.println("No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, Ninety-nine bottles of beer on the wall."); } else{ System.out.println(n +"bottles of beer on the wall, " + n + "bottles of beer." + "Take one down and pass it around, "+ n + "bottles of beer on the wall."); } n--; }while(n>=0); } }

public class beer { public static void main(String[] args) { int _beer = 99; String _first = "bottles of beer on the wall, "; String _second = " bottles of beer."; String _third = "Take one down and pass it around, "; for(int i = 0; i<99; i++) { int counter = 1; System.out.println(_beer + " " + _first + _beer + _second); System.out.println(); _beer--; } } }

public class Bier { public static void main(String[] args) { int flaschen = 99; while (flaschen > 0){ System.out.println(flaschen + " bottles of beer on the wall, "+ flaschen + " bottles of beer. " + "\n Take one down and pass it around, " + flaschen + " bottles of beer on the wall."); --flaschen; } } }

class Test { public static void bottles() { for(int zaehler = 99; zaehler > 1; zaehler--) { System.out.println(zaehler + " bottles of beer on the wall, " + zaehler + " bottles of beer.\nTake one down and pass it around, " + zaehler + " bottles of beer on the wall.\n"); } System.out.println("One last bottle of beer on the wall, one last bottle of beer.\nTake it down, pass it around, no more bottles of beer on the wall."); } public static void main (String[] args) throws java.lang.Exception { bottles(); } }

public class beerbottles { public static void main(String[] args) { for(int i = 99; i > 0; i--) { if(i == 2) { System.out.println(i + " bottles of beer on the wall, " + i + " bottles of beer."); System.out.println("Take one down and pass it around, one last bottle of beer on the wall.\n"); } else if(i == 1) { System.out.println("One last bottle of beer on the wall, one last bottle of beer."); System.out.println("Take it down, pass it around,\nNo more bottles of beer on the wall."); } else { System.out.println(i + " bottles of beer on the wall, " + i + " bottles of beer."); System.out.println("Take one down and pass it around, " + (i-1) + " bottles of beer on the wall.\n"); } } } }