Answer:
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int inputYear;
boolean isLeapYear;
isLeapYear = false;
inputYear = scnr.nextInt();
// A year is considered a leap year if it can be divided evenly by 400,
if (inputYear % 400 == 0)
isLeapYear = true;
// However, if a year can be evenly divided by 100, it is not a leap year
if (inputYear % 100 == 0)
isLeapYear = false;
// If a year can be divided by 4, that year will be a leap year
if (inputYear % 4 == 0)
isLeapYear = true;
if(isLeapYear)
System.out.println(inputYear + " is a leap year.");
else
System.out.println(inputYear + " is not a leap year.");
}
}
Explanation:
If a year is divisible by 400, then the variable isLeapYear is set to true. If a year is a century, divisibility by 100 means it can't be a leap year. When a year meets the criteria of divisibility by 4, it is considered a leap year.
Finally, check the value of isLeapYear; if true, declare it as a leap year. Otherwise, indicate it is not a leap year.
Output:
1712
1712 is a leap year.