Write a Common Lisp function named leapYear which takes no parameters and returns an ordered list containing all leap years from 1800 though 2020. The list of leapyears must be calculated, no points will be given for a hard-coded list.

Respuesta :

Answer:

Explanation:

The following code is written in Java and uses a series of IF statements and remainder operator (%) to calculate whether or not a year is a Leap Year. If so it is added to the ArrayList of leapYears, If not then it is skipped. Finally, the ArrayList is printed out to the terminal.

public static void leapYear() {

           ArrayList<Integer> leapYears = new ArrayList();

           for (int i = 1800; i <= 2020; i++) {

               if ((i % 4) == 0) {

                   if ((i % 100) == 0) {

                       if ((i % 400) == 0) {

                           leapYears.add(i);

                       }

                   } else {

                       leapYears.add(i);

                   }

               }

           }

           for (int x : leapYears) {

               System.out.println(x);

           }

       }