Home
What's New
Dev Tools
Services
Feedback
Site Map

A fun concept that was introduced on the web is to show the code necessary to "say" 99 Bottles of Beer in different languages.  It is an interesting way to get an initial overview of a language since it requires looping, Ifs and simple system output. 

99 Bottles of Beer in Java

class Bottle {
  public static void main(String args[]) {
   int i, next;
   String container = "bottles";
   String s;

   for (i = 99 ; i > 0 ; i--) {
     s = i + " " + container + " of beer on the wall, " +
         i + " " + container + " of beer, " +
         "take 1 down, pass it around,";
     next = i - 1;
     if (next > 0) {
        if (next == 1) {
           container = "bottle";
        }
        s = s + next + " " + container + " of beer on the wall.";
     } else {
         s = s + "No more bottles of beer on the wall!";
     }
     System.out.println(s);
   }
  }
}

99 Bottles of Beer in JavaScript (including HTML page definition)

<HTML>
<HEAD>
<SCRIPT Language=JavaScript>
function do99Bottles() {
  var i, next;
  var container = "bottles";
  var s;
  for (i = 99 ; i > 0 ; i--) {
     s = i + " " + container + " of beer on the wall, " +
         i + " " + container + " of beer, " +
         "take 1 down, pass it around, ";
     next = i - 1;
     if (next > 0) {
        if (next == 1) {
           container = "bottle";
        }
        s = s + next + " " + container + " of beer on the wall.<BR>";
    } else {
        s = s + "No more bottles of beer on the wall!<BR>";
    }
    document.write(s);
  }
}
</SCRIPT>
</HEAD>
<BODY onLoad="do99Bottles()">
</BODY>
</HTML>

... back to Development Tools Page


Copyright 1997-2017, Woodger Computing Inc.