The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
February 2002

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

XMas Carols

Posted by Matt Gerrans on February 20, 2002 at 1:45 PM

Here is a slightly refactored and simplified version, for a better grade:


import java.io.*;

public class ChristmasSong
{
public static void main (String[] args)
{
for( int verse = 1; verse <= 12; verse++ )
{
System.out.print("On the ");
switch( verse )
{
case 1: System.out.print( verse + "st" ); break;
case 2: System.out.print( verse + "nd" ); break;
case 3: System.out.print( verse + "rd" ); break;
default: System.out.print( verse + "th" ); break;
}
System.out.println(" day of Christmas");
System.out.println("my true love gave to me:");

switch (verse)
{
case 12: System.out.println("Twelve drummers drumming");
case 11: System.out.println("Eleven pipers piping");
case 10: System.out.println("Ten lords a leaping");
case 9: System.out.println("Nine ladies dancing");
case 8: System.out.println("Eight maids a milking");
case 7: System.out.println("Seven swans a swimming");
case 6: System.out.println("Six geese a laying");
case 5: System.out.println("Five golden rings");
case 4: System.out.println("Four calling birds");
case 3: System.out.println("Three French hens");
case 2: System.out.println("Two turtle doves, and");
case 1: System.out.println("A partridge in a pear tree");
}

System.out.println();
}
}
}





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us