Created
November 6, 2019 05:31
-
-
Save gitaficionado/c57430bd625bbafd757a9eee8993b06f to your computer and use it in GitHub Desktop.
(Display leap years) Write a program that displays all the leap years, ten per line, from 101 to 2100, separated by exactly one space. Also display the number of leap years in this period
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DisplayLeapYear_Exercise05_27 { | |
public static void main(String[] args) { | |
int count = __; | |
for (int year = ___; year <= ______; year++) { | |
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) | |
System.out.print((++count % 10 == 0)? year + "\n": year + " "); | |
} | |
System.out.println("The number of leap year is " + count); | |
} | |
} | |
/** Version 2 | |
public class Exercise05_27 { | |
public static void main(String[] args) { | |
int count = 0; | |
for (int year = 101; year <= 2100; year++) { | |
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) { | |
++count; | |
System.out.print((count % 10 == 0)? year + "\n": year + " "); | |
} | |
} | |
System.out.println("The number of leap year is " + count); | |
} | |
} | |
*/ | |
/* Version 3 | |
public class Exercise05_27 { | |
public static void main(String[] args) { | |
int count = 0; | |
for (int year = 101; year <= 2100; year++) { | |
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) { | |
++count; | |
if (count % 10 == 0) | |
System.out.print(year + "\n"); | |
else | |
System.out.print(year + " "); | |
} | |
} | |
System.out.println("The number of leap year is " + count); | |
} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment