12 days of xmas??? not showing
i wrote this but my song isnt showing up.
Code java:
import javax.swing.*;
public class Assign5 {
public static void main( String args[] )
{
String result = "";
JTextArea songArea = new JTextArea(20, 30);
JScrollPane scroller = new JScrollPane(songArea);
String songString = "";
for ( int day = 1; day <= 12; day++ ) {
result += "\nOn the " + day;
switch( day ) {
case 1:
result += "st";
break;
case 2:
result += "nd";
break;
case 3:
result += "rd";
break;
default:
result += "th";
break;
}
result += " day of Christmas, my true love gave to me: ";
switch( day ) {
case 12:
result += " Twelve lords-a-leaping, ";
case 11:
result += " Eleven pipers piping, ";
case 10:
result += " Ten drummers drumming, ";
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 turtle doves, and ";
case 1:
result += " a Partridge in pear tree.";
}
}
songArea.setText(songString);
JOptionPane.showMessageDialog(null, scroller, "Twelve Days of Christmas",
JOptionPane.PLAIN_MESSAGE);
System.exit( 0 );
}
}
Re: 12 days of xmas??? not showing
For future reference, please flank your code with the code/highlight tags (see Announcements - What's Wrong With My Code for instructions). I've edited your post for you this time.
Now to the problem...you've set the JTextArea text to the variable songString - look closely at the code and determine what this variable's value might be. To be sure, add a System.out.println statement to print out songString and see what its value is...and at the same time, add another System.out.println statement to print out the variable result.