fork download
  1. class TwelveDaysOfChristmas {
  2.  
  3. public static final String[] lines = new String[] {
  4. "A partridge in a pear tree",
  5. "Two turtle doves and",
  6. "Three French Hens,",
  7. "Four calling birds",
  8. "Five golden rings.",
  9. "Six geese a-laying,",
  10. "Seven swans a-swimming,",
  11. "Eight maids a-milking,",
  12. "Nine ladies dancing,",
  13. "Ten lords a-leaping,",
  14. "Eleven Pipers piping,",
  15. "Twelve drummers drumming,"
  16. };
  17.  
  18. public static final String[] days = new String[] {
  19. "first",
  20. "second",
  21. "third",
  22. "fourth",
  23. "fifth",
  24. "sixth",
  25. "seventh",
  26. "eighth",
  27. "ninth",
  28. "tenth",
  29. "eleventh",
  30. "twelfth"
  31. };
  32.  
  33. public static void main(String[] args) {
  34. try {
  35. recurseDown(0);
  36. } catch (RuntimeException e) {
  37. // nothing.
  38. }
  39. }
  40.  
  41. private static void recurseDown(int i) {
  42. System.out.println("\nOn the " + days[i] + " day of Christmas\nMy true love sent to me");
  43. try {
  44. recurseUp(i);
  45. } catch (RuntimeException e) {
  46. // nothing.
  47. }
  48. recurseDown(i + 1);
  49. }
  50.  
  51. private static void recurseUp(int i) {
  52. System.out.println(lines[i]);
  53. recurseUp(i - 1);
  54. }
  55. }
Success #stdin #stdout 0.1s 320704KB
stdin
Standard input is empty
stdout
On the first day of Christmas
My true love sent to me
A partridge in a pear tree

On the second day of Christmas
My true love sent to me
Two turtle doves and
A partridge in a pear tree

On the third day of Christmas
My true love sent to me
Three French Hens,
Two turtle doves and
A partridge in a pear tree

On the fourth day of Christmas
My true love sent to me
Four calling birds
Three French Hens,
Two turtle doves and
A partridge in a pear tree

On the fifth day of Christmas
My true love sent to me
Five golden rings.
Four calling birds
Three French Hens,
Two turtle doves and
A partridge in a pear tree

On the sixth day of Christmas
My true love sent to me
Six geese a-laying,
Five golden rings.
Four calling birds
Three French Hens,
Two turtle doves and
A partridge in a pear tree

On the seventh day of Christmas
My true love sent to me
Seven swans a-swimming,
Six geese a-laying,
Five golden rings.
Four calling birds
Three French Hens,
Two turtle doves and
A partridge in a pear tree

On the eighth day of Christmas
My true love sent to me
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings.
Four calling birds
Three French Hens,
Two turtle doves and
A partridge in a pear tree

On the ninth day of Christmas
My true love sent to me
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings.
Four calling birds
Three French Hens,
Two turtle doves and
A partridge in a pear tree

On the tenth day of Christmas
My true love sent to me
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings.
Four calling birds
Three French Hens,
Two turtle doves and
A partridge in a pear tree

On the eleventh day of Christmas
My true love sent to me
Eleven Pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings.
Four calling birds
Three French Hens,
Two turtle doves and
A partridge in a pear tree

On the twelfth day of Christmas
My true love sent to me
Twelve drummers drumming,
Eleven Pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings.
Four calling birds
Three French Hens,
Two turtle doves and
A partridge in a pear tree