Answers for "write a program that prints the next 20 leap years."

2

Write a program that prints the next 20 leap years.

public class Main {
  public static void main(String[] args) {
    var scanner = new java.util.Scanner(System.in);
    System.out.print("What is the current year? ");
    int year = scanner.nextInt() + 1;
    int count = 0;
    while (count < 20) {
      if (year % 4 == 0) {
        if (year % 100 != 0 || year % 400 == 0) {
          ++count;
          System.out.println(year);
        }
      }
      ++year;
    }
  }
}
Posted by: Guest on January-25-2021
0

write a program that prints the next 20 leap years.

2024
2040
Posted by: Guest on July-04-2021

Code answers related to "write a program that prints the next 20 leap years."

Browse Popular Code Answers by Language