a program which has one method that takes int "Year" as a parameter which then based on the parameter figures out whether it is a leap year or not. Theyve given a table showing which is not and which is a leap year
2010 /4 = no .. /100 = no .. /400 = no .. leap = no
2012 /4 = yes .. /100 = no .. /400 = no .. leap = yes
1900 /4 = yes .. /100 = yes .. /400 = no .. leap = no
2000 /4 = yes .. /100 = yes .. /400 = yes .. leap = yes
They also want the method to identify if a year is before the gregorian calendar 1565
Below is the current code I have done. It works for some years and doesnt for others. Obviously im doing something wrong. Any help would be greatly appreaciated if someone could inform me what Im doing right and what Im doing wrong or how best to go about this?
public class theleapyear{
public static void main( String [] args){
leapyear(2010);
leapyear(2012);
leapyear(1900);
leapyear(2000);
leapyear(1565);
}
public static void leapyear( int year){
if (year < 1565)
System.out.println( year + ":" + " predates the Gregorian Calendar ");
else
if (year % 4 != 0)
if (year % 100 != 0)
if (year % 400 != 0)
{
System.out.println( year + ":" + " is not a leap year ");
}
else
{
if (year % 4 == 0)
if (year % 100 != 0)
if (year % 400 != 0)
System.out.println( year + ":" + " is a leap year ");
}
else
{
if (year % 4 == 0)
if (year % 100 == 0)
if (year % 400 != 0)
System.out.println( year + ":" + " is not a leap year ");
}
else
{
if (year % 4 == 0)
if (year % 100 == 0)
if (year % 400 == 0)
System.out.println( year + ":" + " is a leap year ");
}
}
}