1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Programming the 12 days of Christmas in Java

Discussion in 'Software Development' started by Rhino24, Feb 10, 2008.

Thread Status:
Not open for further replies.
  1. Rhino24

    Rhino24 Thread Starter

    Feb 8, 2008
    Is this a Good way to program the 12 days of Christmas in Java. Feel free to make modifications are if I am doing it completely wrong.

    class christmas {
    public static void main(String[] args) {
    int number;
    System.out.print("Enter number: ");
    number = 12;

    for(int i=1; i<=number; i++) {
    System.out.print("On the ");
    switch(i) {
    case 1: System.out.print("1st"); break;
    case 2: System.out.print("2nd"); break;
    case 3: System.out.print("3rd"); break;
    default: System.out.print(i+"th");
    System.out.println(" day of Christmas my true love gave to me");
    switch(i) {
    case 12: System.out.print("twelve drummers drumming, ");
    case 11: System.out.println("eleven pipers piping, ");
    case 10: System.out.print("ten lords a-leping, ");
    case 9: System.out.print("nine ladies dancing, ");
    case 8: System.out.println("eight maids a-milking, ");
    case 7: System.out.print("seven swans a-swimming, ");
    case 6: System.out.print("six geese a-laying, ");
    case 5: System.out.println("five gold rings,");
    case 4: System.out.print("four calling birds, ");
    case 3: System.out.print("three french hens, ");
    case 2: System.out.print("two turtle doves\nand ");
    case 1: System.out.println("a partridge in a pear tree.");
  2. Chicon


    Jul 29, 2004
    Except for 2 missing } at the end of your coding, it works.
    You should initialize an array of 12 String items to store the text parts. Beware, the first index of an array is 0.
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/681553