KnowledgeBoat Logo

Computer Applications

Write a program to input year and check whether it is:

(a) a Leap year

(b) a Century Leap year

(c) a Century year but not a Leap year

Sample Input: 2000
Sample Output: It is a Century Leap Year.

Java

Java Conditional Stmts

183 Likes

Answer

import java.util.Scanner;

public class KboatCenturyLeapYear
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the year to check: ");
        int yr = in.nextInt();

        if (yr % 4 == 0 && yr % 100 != 0)
            System.out.println("It is a Leap Year");
        else if (yr % 400 == 0)
            System.out.println("It is a Century Leap Year");
        else if (yr % 100 == 0)
            System.out.println("It is a Century Year but not a Leap Year");
        else
            System.out.println("It is neither a Century Year nor a Leap Year");
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of Write a program to input year and check whether it is: (a) a Leap year (b) a Century Leap year (c) a Century year but not a Leap year Sample Input: 2000 Sample Output: It is a Century Leap Year.

Answered By

65 Likes


Related Questions