Advertisement
LightProgrammer000

The Twelve Days of Christmas

Feb 24th, 2020
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.11 KB | None | 0 0
  1. // Pacote
  2. package Tarefas_1;
  3.  
  4. public class EX_12
  5. {
  6.     public static void main(String[] args)
  7.     {
  8.         System.out.println("# Programa EX_12");
  9.  
  10.         try
  11.         {
  12.             // Execucao do programa
  13.             exec_program();
  14.         }
  15.  
  16.         catch (Exception e)
  17.         {
  18.             //System.err.println(e);        
  19.         }
  20.     }
  21.  
  22.     // Metodo: Programa principal
  23.     private static void exec_program()
  24.     {
  25.         // Variaveis: Lista numerica
  26.         String lista_num [] = {"first","second","third","fourth",
  27.                                "fifth","sixth","seventh","eighth",
  28.                                "ninth","tenth","eleventh","twelfth"};
  29.  
  30.         // Variaveis: Lista de estrofes
  31.         String lista [] = {"a partridge in a pear tree.",
  32.                            "two turtle doves,",
  33.                            "three french hens,",
  34.                            "four calling birds,",
  35.                            "five gold rings,",
  36.                            "six geese a-laying,",
  37.                            "seven swans a-swimming,",
  38.                            "eight maids a-milking,",
  39.                            "nine ladies waiting,",
  40.                            "ten lords a-leaping,",
  41.                            "eleven pipers piping,",
  42.                            "twelve drummers drumming,"};
  43.  
  44.         // Apresentacao: Estrofe [1]
  45.         System.out.println("\nOn the " + lista_num[0] + " day of Christmas, my love gave to me \n" + lista[0]);
  46.  
  47.         // Estrutura de repeticao
  48.         for (int i = 1; i < lista.length ; i++)
  49.         {
  50.             System.out.println("\nOn the " + lista_num[i] + " day of Christmas, my love gave to me ");
  51.  
  52.             // Estrutura de repeticao
  53.             for (int j = i; j >= 0 ; j--)
  54.             {
  55.                 // Estrutura de decisao
  56.                 if (j == 0)
  57.                 {
  58.                     System.out.println("and " + lista[j]);
  59.                 }
  60.  
  61.                 else
  62.                 {
  63.                     System.out.print(lista[j] + "\n");                
  64.                 }
  65.             }
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement