In: Computer Science
CS 206 Visual Programming, Netbeans
Problem: Write a Java program that displays all the leap years, 10
per line, from 1001 to 2100, separated by exactly one space. Also
display the total number of leap years in this period. Hints: you
need to use a loop ( for-loop is more suitable)
//TestCode.java public class TestCode { public static boolean isLeapYear(int userYear){ if(userYear % 4 == 0 && userYear % 100 != 0){ return true; } else if(userYear % 400 == 0){ return true; } return false; } public static void main(String[] args) { int k = 1; for(int i = 1001;i<=2100;i++){ if(k%10==0){ System.out.println(); k = 1; } if(isLeapYear(i)){ System.out.print(i+" "); k++; } } } }