TwelveDays - System.out.print"rd" break default...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // TwelveDays.java Author: Lewis and Loftus // // Solution to Programming Project 3.17 //******************************************************************** / import java.util.Scanner; i public class TwelveDays { //----------------------------------------------------------------- // Prints the song "The Twelve Days of Christmas". //----------------------------------------------------------------- public static void main (String[] args) { final int MAX = 12; int lastDay = 0; // Last day for the song Scanner sc = new Scanner(System.in); while (lastDay < 1 || lastDay > MAX) { System.out.print ("How many days (1 to " + MAX + ")? "); lastDay = sc.nextInt(); } for (int day = 1; day <= lastDay; day++) { System.out.print ("On the " + day); switch (day) { case 1: System.out.print ("st"); break; case 2: System.out.print ("nd"); break; case 3:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: System.out.print ("rd"); break; default: System.out.print ("th"); } System.out.println (" day of Christmas my true love gave to" + " me"); switch (day) { case 12: System.out.println ("Twelve drummers drumming,"); case 11: System.out.println ("Eleven pipers piping,"); case 10: System.out.println ("Ten lords a leaping,"); case 9: System.out.println ("Nine ladies dancing,"); case 8: System.out.println ("Eight maids a milking,"); case 7: System.out.println ("Seven swans a swimming,"); case 6: System.out.println ("Six geese a laying,"); case 5: System.out.println ("Five golden rings,"); case 4: System.out.println ("Four calling birds,"); case 3: System.out.println ("Three French hens,"); case 2: System.out.println ("Two turtle doves, and"); default: System.out.println ("A partridge in a pear tree."); } System.out.println(); } } }...
View Full Document

This note was uploaded on 05/17/2011 for the course COP 3530 taught by Professor Davis during the Spring '08 term at University of Florida.

Page1 / 2

TwelveDays - System.out.print"rd" break default...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online