Java :: Aufgabe #43

6 Lösungen Lösungen öffentlich

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.

Lösungen:

vote_ok
von maxator (120 Punkte) - 15.01.2013 um 23:22 Uhr
Quellcode ausblenden Java-Code
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");
    }
  }
}
1x
vote_ok
von bequiet (220 Punkte) - 27.06.2013 um 13:25 Uhr
Quellcode ausblenden Java-Code
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);
		

	}

}
vote_ok
von PTPHard (540 Punkte) - 27.05.2014 um 22:48 Uhr
Quellcode ausblenden Java-Code
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--;
        }
    }
}
vote_ok
von Salute (220 Punkte) - 30.05.2015 um 20:00 Uhr
Quellcode ausblenden Java-Code
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;
		}
	}

}
vote_ok
von Bufkin (1410 Punkte) - 16.08.2017 um 14:51 Uhr
Quellcode ausblenden Java-Code
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();
     }
}
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");
			}
		}
	}
}
2095403

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.