Question
Assignment: Write a Java Class that computes and prints all the leap years between a starting and ending year. A year is a leap year
Assignment: Write a Java Class that computes and prints all the leap years between a starting and ending year. A year is a leap year if it meets one of the two conditions below:
A year is a leap year if it is divisible by 4 and not divisible by 100 (For example, 1980).
A year is a leap year if it is divisible by 400 (for example, 2000) Write a program that does the following:
1. Prompts the user for the starting year
2. Prompts the user for the ending year
3. Prints all the leap years between the start year and the ending year separated by a space
4. Ten years or less will be printed on each separate line of output
5. At the end, the program will print the total number of leap years between the start and end years entered by the user
Sample Output:
Enter the starting year
1900
Enter the ending year
2000
1904 1908 1912 1916 1920 1924 1928 1932 1936 1940
1944 1948 1952 1956 1960 1964 1968 1972 1976 1980
1984 1988 1992 1996 2000
There are 25 years between 1900 and 2000
The general algorithm would be:
Loop year from start year to end year, and inside the loop perform a compound if statement (or several simple if statements) to determine if year is a leap year:
o If year is a leap year: 1) print it; 2) add one to a counter; 3) determine if you need to move to the next line. After the loop, print the counter
Use only Loop
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started