Ask Question
3 March, 12:23

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).

+2
Answers (1)
  1. 3 March, 14:49
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers