Write a program in java 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 (0 to stop): 1960
1960 is a leap year.
Enter a year (0 to stop): 1996
1996 is a leap year.
Enter a year (0 to stop): 2000
2000 is a leap year.
Enter a year (0 to stop): 1961
1961 is not a leap year.
Enter a year (0 to stop): 1995
1995 is not a leap year
Enter a year (0 to stop): 1900
1900 is not a leap year
Enter a year (0 to stop): 0
Bye.
Hint:
Leap year alg. from wiki:
if (year is
not divisible (Links to an external site.) (Links to
an external site.) 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)
Write a program in java that determines if a given year is a leap year. Leap years are those years that are divisible by
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Write a program in java that determines if a given year is a leap year. Leap years are those years that are divisible by
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!