java next 20 leap years code example
Example: 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;
}
}
}