Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Vala

Date:04/16/07
Author:Kahnamta
URL:n/a
Comments:2
Info:http://live.gnome.org/Vala
Score: (2.81 in 101 votes)
/* 99 Bottles of Beer in Vala (live.gnome.org/Vala)
   by Kahnamta, Apr 15 2007 */

using GLib;

public class Beer {
        private int bottles = 99;

        public void drink() {
                if (bottles > 2) {
                        stdout.printf("%d bottles of beer on the wall.\n", bottles);
                        stdout.printf("%d bottles of beer.\n", bottles);
                        stdout.printf("Take one down, pass it around\n");
                        stdout.printf("%d bottles appear on the wall!\n\n", --bottles);

                        drink();
                }
                else if (bottles == 2) {
                        stdout.printf("Two bottles of beer on the wall.\n");
                        stdout.printf("Two bottles of beer.\n");
                        stdout.printf("Take one down, pass it around\n");
                        stdout.printf("One bottle appear on the wall!\n\n");
                        bottles--;

                        drink();
                }
                else {
                        stdout.printf("One bottle of beer on the wall.\n");
                        stdout.printf("One bottle of beer.\n");
                        stdout.printf("Take it down, pass it around\n");
                        stdout.printf("No more bottles appear on the wall!\n\n");
                }
        }

        static int main(string[] args) {
                var bottle = new Beer();

                bottle.drink();

                return 0;
        }
}

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
SignalsHohoo03/26/101

Comments

>>  vlad said on 04/11/09 22:11:09

vlad No class required in Vala (as opposed to Java, C#).

>>  Pat said on 03/11/10 08:32:14

Pat It's "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."

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: