My problem is for my output the first three days are giving me the incorrect output. I get:
On the 1stndrdth day of Christmas
On the 2ndrdth day of Christmas
On the 3rdth day of Christmas
And it should obviously only be: 1st, 2nd, 3rd. Maybe it's staring at the screen too long but I can't see my misstep. Can somebody provide some guidance as to what I have structured incorrectly? Thank you.
/**
* This class outputs the 12 days of christmas song
*
* @author
* @version
*/
public class ChristmasSong
{
public static void main ( String [] args )
{
String result = "";
for ( int day = 1; day <= 12; day++ )
{
result += "\nOn the " + day;
switch ( day )
{
case 1:
result += "st";
case 2:
result += "nd";
case 3:
result += "rd";
default:
result += "th";
}
result += " day of Christmas, my true love gave to me: ";
switch ( day )
{
case 12:
result += " Twelve drummers drumming, ";
case 11:
result += " Eleven pipers piping, ";
case 10:
result += " Ten lords-a-leaping, ";
case 9:
result += " Nine ladies dancing, ";
case 8:
result += " Eight maids-a-milking, ";
case 7:
result += " Seven swans-a-swimming, ";
case 6:
result += " Six geese-a-laying, ";
case 5:
result += " Five golden rings.";
case 4:
result += " Four calling birds, ";
case 3:
result += " Three French hens, ";
case 2:
result += " Two turle doves, and ";
case 1:
result += " a Patridge in a pear tree.";
}
}
System.out.println ( result );
}
}

New Topic/Question
Reply



MultiQuote



|