According to Wikipedia
A “hello world” program is a computer program that prints out “Hello, World!” on a display device. It is used in many introductory tutorials for teaching a programming language. Such a program is typically one of the simplest programs possible in a computer language.
An example using the Java programming language looks like
—————————-
// Hello World in Java
public class HelloWorld {
static public void main( String args[] ) {
System.out.println( "Hello World!" );
}
}
—————————-
Again, all this program does is output “Hello World” to the screen.
A wonderfully rich collection of Hello World program examples is maintained here.
—————————-
A slightly more complex programming task for the beginner would be a “Hello Caractacus” program. The goal of this program is to output the lyrics to Rolf Harris’ deeply philosophical song “The Court of King Caractacus. This task has more oomph to it because it requires the programmer to understand how the song builds upon itself.
I have written the following example (again in Java).
—————————-
public class HelloCaractacus {
public static final String TITLE = "the court of king caracticus by rolf harris\n";
public static final String [] lyrics = {
"the ladies of the harem of the court of king caractacus ",
"the noses on the faces of ",
"the boys who put the powder on ",
"the fascinating witches who put the scintillating stiches in the britches of ",
};
public static final String[] BEGINNINGS = {
"now ",
"if you want to take a picture of "
};
public static final String[] ENDINGS = {
"were just passing by.",
"well it's too late! coz they've just passed by!"
};
public static final String[] COMMANDS = {
"[all together]"
};
public static void main (String [] args) {
jotln(TITLE);
// for each verse
for (int i=0;i<4;i++) {
// repeat three times
for (int j=0;j<4;j++) {
if (j==1) {
jotln(COMMANDS[0]);
}
jot(BEGINNINGS[0]); // now
// join the appropriate bits together
for (int k=i;k>=0;k–) {
jot(lyrics[k]);
}
jotln(ENDINGS[0]); // were just passing by
}
jotln(”"); // blank line
}
// photo opportunity
for (int i=0;i<2;i++) {
jot(BEGINNINGS[i]);
}
// the longest line
for (int k=3;k>=0;k–) {
jot(lyrics[k]);
}
jotln(ENDINGS[1]); // you are too late
}
public static void jot(String s) { System.out.print(s); } // for
public static void jotln(String s) { System.out.println(s); } // brevity
}
—————————-
The program outputs the following:
—————————-
the court of king caracticus by rolf harris
now the ladies of the harem of the court of king caractacus were just passing by.
[all together]
now the ladies of the harem of the court of king caractacus were just passing by.
now the ladies of the harem of the court of king caractacus were just passing by.
now the ladies of the harem of the court of king caractacus were just passing by.
now the noses on the faces of the ladies of the harem of the court of king caractacus were just passing by.
[all together]
now the noses on the faces of the ladies of the harem of the court of king caractacus were just passing by.
now the noses on the faces of the ladies of the harem of the court of king caractacus were just passing by.
now the noses on the faces of the ladies of the harem of the court of king caractacus were just passing by.
now the boys who put the powder on the noses on the faces of the ladies of the harem of the court of king caractacus were just passing by.
[all together]
now the boys who put the powder on the noses on the faces of the ladies of the harem of the court of king caractacus were just passing by.
now the boys who put the powder on the noses on the faces of the ladies of the harem of the court of king caractacus were just passing by.
now the boys who put the powder on the noses on the faces of the ladies of the harem of the court of king caractacus were just passing by.
now the fascinating witches who put the scintillating stiches in the britches of the boys who put the powder on the noses on the faces of the ladies of the harem of the court of king caractacus were just passing by.
[all together]
now the fascinating witches who put the scintillating stiches in the britches of the boys who put the powder on the noses on the faces of the ladies of the harem of the court of king caractacus were just passing by.
now the fascinating witches who put the scintillating stiches in the britches of the boys who put the powder on the noses on the faces of the ladies of the harem of the court of king caractacus were just passing by.
now the fascinating witches who put the scintillating stiches in the britches of the boys who put the powder on the noses on the faces of the ladies of the harem of the court of king caractacus were just passing by.
now if you want to take a picture of the fascinating witches who put the scintillating stiches in the britches of the boys who put the powder on the noses on the faces of the ladies of the harem of the court of king caractacus well it’s too late! coz they’ve just passed by!
—————————-
THOUGHTS
1. Writing Hello Caractacus is not an overly complex task. High school students should have no trouble with it. The requirement itself is clear; as an exercise in logical thinking it works well.
2. If anyone knows of a site that allows you to paste simple Java source code (like that above) and does an online compile and run, please let me know.
3. There are always more that one way to do any task. The way I have done it here is the way my fingers prefer to do it. Quick and dirty some may say. Alternative approaches are welcome, especially if (rather than express personal style) they add value. This is not a scenario where design patterns and other software engineering fluff should be applied. However, alternatives that are clever, obscure and playful are most welcome, provided the basic version comes first.
4. Ideally examples in other programming languages would be good to see as well. I suggest that if you are up to the task, and have a language you would like to volunteer and example using, would could build up quite a collection.