Ask Question
9 January, 01:11

Write a program that determines if a given year is a leap year. Leap years are those years that are divisible by four, except that century years not divisible by 400 are not leap years. For example, 1960, 1996, and 2000 are leap years, while 1961, 1995, and 1900 are not. Your program should ask the user to enter a year and then determine whether that year is a leap year. Repeat until the user enters 0 for the year. The following is an example program run (the user's input is underlined). Enter a year: 1960 1960 is a leap year. Hint: Leap year alg. from wiki: if (year is not divisible by 4) then (it is a common year) else if (year is not divisible by 100) then (it is a leap year) else if (year is not divisible by 400) then (it is a common year) else (it is a leap year).

+5
Answers (1)
  1. 9 January, 04:15
    0
    Java program given below

    Explanation:

    import java. util. Scanner;

    public class LeapYearCheck {

    public static void main (String[] args) {

    Scanner in=new Scanner (System. in);

    while (true)

    {

    System. out. print ("Enter a year (0 to stop) : ");

    int year=in. nextInt ();

    / / System. out. println ();

    if (year==0)

    {

    System. out. println ("Bye.");

    break;

    }

    boolean leap = false;

    if (year % 4 = = 0)

    {

    if (year % 100 = = 0)

    {

    if (year % 400 = = 0)

    leap = true;

    else

    leap = false;

    }

    else

    leap = true;

    }

    else

    leap = false;

    if (leap)

    System. out. println (year + " is a leap year.");

    else

    System. out. println (year + " is not a leap year.");

    }

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program that determines if a given year is a leap year. Leap years are those years that are divisible by four, except that century ...” in 📘 Engineering if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers