Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class LeapYears {
- /* Determine whether a particular year is a leap year or not and use this method
- inside a new method to determine a subsequent leap year. */
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.println("This program calculates leap years.");
- System.out.print("Enter the year: ");
- int year = scan.nextInt();
- if (year<1582) {
- System.out.println("Error! Gregorian Calendar only started in 1582.");
- return;
- } // if
- if (isLeapYear(year)) {
- System.out.println (year +" is a leap year.");
- } else {
- System.out.println (year +" is not a leap year.");
- } // if
- year = findNextLeapYear(year);
- System.out.println ("The next leap year is " + year);
- } // main()
- public static int findNextLeapYear(int year) {
- while (!isLeapYear(++year));
- return year;
- } // findNextLeapYear()
- public static boolean isLeapYear(int year) {
- return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
- } // isLeapYear()
- } // class LeapYears
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement