Question

How to start a java program for 12 days of Christmas lyrics using if statements.

How to start a java program for 12 days of Christmas lyrics using if statements.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class main{

public static void main(String[] args) {
   int days;
   System.out.print("Enter number: ");
days =12;
   System.Out.Println()

//using for loop

for(int i=1; i<=number; i--) {
   System.out.print("On the ");

   if(i==1){

System.out.print("first");

//breaking the loop

break;

}
   if(i==2){

System.out.print("second");

//breaking the loop

break;

}
   if(i==3){

System.out.print("third");

//breaking the loop

break;

}
if(i==4){

System.out.print("fourth");

//breaking the loop

break;

}

if(i==5){

System.out.print("fifth");

//breaking the loop

break;

}

if(i==6){

System.out.print("sixth");

//breaking the loop

break;

}

if(i==7){

System.out.print("seventh");

//breaking the loop

break;

}

if(i==8){

System.out.print("eighth");

//breaking the loop

break;

}

if(i==9){

System.out.print("ninth");

//breaking the loop

break;

}

if(i==10){

System.out.print("tenth");

//breaking the loop

break;

}

if(i==11){

System.out.print("eleventh");

//breaking the loop

break;

}

if(i==12){

System.out.print("twelth");

//breaking the loop

break;

}

System.out.println(" day of Christmas my true love gave to me");

if(i==12)

System.out.print("twelve drummers drumming, ");


   if(i==11)

System.out.println("eleven pipers piping, ");


   if(i==10)

System.out.print("ten lords a-leping, ");
   if(i==9)

System.out.print("nine ladies dancing, ");

if(i==8)

System.out.println("eight maids a-milking, ");


   if(i==7)

System.out.print("seven swans a-swimming, ");


   if(i==6)

System.out.print("six geese a-laying, ");


   if(i==5)

System.out.println("five gold rings,");


   if(i==4)

System.out.print("four calling birds, ");


   if(i==3)

System.out.print("three french hens, ");


   if(i==2)

System.out.print("two turtle doves\nand ");


   if(i==1)

System.out.println("a partridge in a pear tree.");

   }// end for
  } // end main

} // end class

Add a comment
Know the answer?
Add Answer to:
How to start a java program for 12 days of Christmas lyrics using if statements.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT