public class JavaApplication1
{
public static void main(String[] args)
{
try
{
int[] years = {2000, 2400, 1800, 1900, 2100, 2200, 2300, 2500,
2008, 2012, 2016, 2020, 2024, 2048, 2032};
for (int yr : years)
{
if (isLeapYear(yr))
System.out.format("%d is a leap year.\n", yr);
else
System.out.format("%d is not a leap year.\n", yr);
}
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
static boolean isLeapYear(int year)
{
if (year % 400 == 0)
return true;
else if (year % 100 == 0)
return false;
else if (year % 4 == 0)
return true;
return false;
}
}
/*
run:
2000 is a leap year.
2400 is a leap year.
1800 is not a leap year.
1900 is not a leap year.
2100 is not a leap year.
2200 is not a leap year.
2300 is not a leap year.
2500 is not a leap year.
2008 is a leap year.
2012 is a leap year.
2016 is a leap year.
2020 is a leap year.
2024 is a leap year.
2048 is a leap year.
2032 is a leap year.
*/