ITEC 120 LAB 7 Back to Lab index page

Leap Year

You will write Java program that will ask the user to enter a year. Your program will then tell the user whether or not the year is a leap year. The program will then ask the user to enter another number. To quit the program, the user will enter 0 (zero).

A year is a leap year if it is divisible by 4 but not by 100. A year that is divisible by both 4 and 100 is a leap year if it is also divisible by 400. (Example: 2000 is a leap year, but 1800 is not.)

Sample run

Program outputs:

Welcome to the leap year detector.

Please enter a year (0 to quit):

User inputs: 2000
Program outputs:

2000 is a leap year.

Please enter another (0 to quit):

User inputs: 1796
Program outputs:

1796 is a leap year.

Please enter another (0 to quit):

User inputs: 1800
Program outputs:

1800 is not a leap year.

Please enter another (0 to quit):

User inputs: 2001
Program outputs:

2001 is not a leap year.

Please enter another (0 to quit):

User inputs: 0
Program outputs: Thank you for using the leap year detector.
You entered 4 years.
Goodbye!

Be sure to include a "hello" message and the "goodbye" message that run only once at the beginning and end of the program. Also, at the end of the program include a message that tells the user how many years they entered.

Once you have your program working, show your lab to the Peer Instructor to be checked off. The Peer Instructor will run the program.