-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwelveDays.java
More file actions
38 lines (34 loc) · 1.42 KB
/
TwelveDays.java
File metadata and controls
38 lines (34 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class TwelveDays{
public static void main(String[] args){
//declare array with gifts
String[] gifts = {"Drummers Drumming", "Pipers Piping", "lords a leaping", "ladies dancing", "maids a milking", "swans a swimming", "geese a laying", "golden rings", "calling birds", "french hens", "turtle doves", "A Partridge in a pear tree"};
int dayCount = 0; //declaring a variable to store count of days
String day;
String[] giftedGifts = new String[12];
for(int i = 0; i < gifts.length; i++){ //for loo to go through each gift in array
//try{
//Thread.sleep(1000); //program sleeps for one second so there is one second delay between output
//}catch(InterruptedException e){}
giftedGifts[dayCount] = gifts[i];
dayCount++;
//following block of code will decide the correct ending to use
if(dayCount == 1){
day = dayCount + "st";
}else if(dayCount == 2){
day = dayCount + "nd";
}else if(dayCount == 3){
day = dayCount + "rd";
}else{
day = dayCount + "th";
}
System.out.println("On the " + day + " day of Christmas my true love gave to me: ");
for(int j = 0; j <= i; j++){ //outputting all gifts for the current day and all days lower
if(j == gifts.length - 1){
System.out.println("and " + gifts[j]);
}else{
System.out.println(dayCount + " " + gifts[j]);
}
}
}
}
}