www.webdeveloper.com
Results 1 to 2 of 2

Thread: 12 days of christmas please help!

Hybrid View

  1. #1
    Join Date
    Jan 2014
    Posts
    5

    12 days of christmas please help!

    Hello I am currently on a break from University I need help with the last part of this work I really cant wrap my head around it. Basically I need to change the switch into ifs so that it still works, here is the code I have with the switch:

    public class christmas {

    public static void main(String[] args) {
    int number;
    System.out.print("Enter number: ");
    //number=readInt();
    number = 1;
    System.out.println();

    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.");
    }
    System.out.println();

    }}}
    Please help.

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,350
    Wrong forum.

    This is JavaScript forum, not the Java forum.

    You will probably get a better response there.



    Probably missing the 'break's after each case. See: http://docs.oracle.com/javase/tutori...ts/switch.html
    Last edited by JMRKER; 01-08-2014 at 11:01 AM. Reason: Added link.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles