in java
Write a program that displays all the leap years, eight per line, from 101 to 2500, separated by one space. Meanwhile display the number of leap years in this period of year.
public class PrintLeaps { public static void main(String[] args) { int count = 0; for (int year = 101; year <= 2500; year++) { if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) { System.out.print(year + " "); ++count; if (count % 8 == 0) System.out.println(); } } System.out.println("\nThere were " + count + " leap years from 101 to 2500"); } }
Get Answers For Free
Most questions answered within 1 hours.