Advertisement
brilliant_moves

TwelveDaysOfXmas.java

Oct 6th, 2012
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 2.13 KB | None | 0 0
  1. public class TwelveDaysOfXmas {
  2.  
  3.     /**
  4.     *   Program:    TwelveDaysOfXmas.java
  5.     *   Creator:    Chris Clarke
  6.     *   Created:    06.10.2012
  7.     *   Purpose:    Display the lyrics of the song "The 12 Days of Christmas".
  8.     *           Do so using only one loop.  In the code below, notice
  9.     *           the absence of "break"s in the second "switch" statement.
  10.     *           This causes - intentional - fall-through to the next line.
  11.     */
  12.  
  13.     public static void main(String[] args) {
  14.  
  15.         System.out.println("\n\t=== The Twelve Days of Christmas ===\n");
  16.  
  17.         for (int day=1; day<=12; day++) {
  18.  
  19.             System.out.print("On the ");
  20.  
  21.             switch (day) {
  22.                 case 1:     System.out.print("First" ); break;
  23.                 case 2:     System.out.print("Second" ); break;
  24.                 case 3:     System.out.print("Third" ); break;
  25.                 case 4:     System.out.print("Fourth" ); break;
  26.                 case 5:     System.out.print("Fifth" ); break;
  27.                 case 6:     System.out.print("Sixth" ); break;
  28.                 case 7:     System.out.print("Seventh" ); break;
  29.                 case 8:     System.out.print("Eighth" ); break;
  30.                 case 9:     System.out.print("Ninth" ); break;
  31.                 case 10:    System.out.print("Tenth" ); break;
  32.                 case 11:    System.out.print("Eleventh" ); break;
  33.                 case 12:    System.out.print("Twelfth" ); break;
  34.                 default:    System.out.print("Error" );
  35.             } // end switch
  36.  
  37.             System.out.println(" Day of Christmas, my True Love sent to Me:");
  38.  
  39.             switch (day) {
  40.                 case 12:    System.out.println("12 Drummers Drumming," );
  41.                 case 11:    System.out.println("11 Pipers Piping," );
  42.                 case 10:    System.out.println("10 Lords a-Leaping," );
  43.                 case 9:     System.out.println("9 Ladies Dancing," );
  44.                 case 8:     System.out.println("8 Maids a-Milking," );
  45.                 case 7:     System.out.println("7 Swans a-Swimming," );
  46.                 case 6:     System.out.println("6 Geese a-Laying," );
  47.                 case 5:     System.out.println("5 Gold Rings;" );
  48.                 case 4:     System.out.println("4 Calling Birds," );
  49.                 case 3:     System.out.println("3 French Hens," );
  50.                 case 2:     System.out.println("2 Turtle Doves," );
  51.                 default:    System.out.print(day==1 ? "A " : "And a " );
  52.                         System.out.println("Partridge in a Pear Tree.");
  53.                         System.out.println();
  54.             } // end switch
  55.         } // end for
  56.     } // end main
  57. } // end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement