Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Software Development
Tag Cloud
access audio black screen blue screen bsod connection crash dell desktop drivers dvd email error excel firefox google hard drive hardware hdmi hijackthis internet itunes keyboard laptop malware monitor motherboard network networking outlook problem ram recovery router screen slow sound spyware tdlwsp.dll trojan vba video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Software Development >
Programming the 12 days of Christmas in Java

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
Rhino24's Avatar
Member with 41 posts.
 
Join Date: Feb 2008
Experience: Beginner
10-Feb-2008, 10:43 AM #1
Programming the 12 days of Christmas in Java
Is this a Good way to program the 12 days of Christmas in Java. Feel free to make modifications are if I am doing it completely wrong.

class christmas {
public static void main(String[] args) {
int number;
System.out.print("Enter number: ");
//number=readInt();
number = 12;
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();
Chicon's Avatar
Computer Specs
Distinguished Member with 6,690 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
10-Feb-2008, 01:42 PM #2
Except for 2 missing } at the end of your coding, it works.
You should initialize an array of 12 String items to store the text parts. Beware, the first index of an array is 0.
Closed Thread Bookmark and Share

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 02:44 AM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.