TwelveDays - System.out.print...

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

Page1 / 2

TwelveDays - System.out.print...

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