Java :: Aufgabe #43 :: Lösung #6

6 Lösungen Lösungen öffentlich
#43

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:

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.
#6
vote_ok
von paddlboot (3970 Punkte) - 09.07.2019 um 08:53 Uhr
Quellcode ausblenden Java-Code
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");
			}
		}
	}
}

Kommentare:

Für diese Lösung gibt es noch keinen Kommentar

Bitte melden Sie sich an um eine Kommentar zu schreiben.
Kommentar schreiben
2095590

Du scheinst einen AdBlocker zu nutzen. Ich würde mich freuen, wenn du ihn auf dieser Seite deaktivierst und dich davon überzeugst, dass die Werbung hier nicht störend ist.