Hi the following method does not quite work:
public static int dayInYear(int day, int month, int year) {
// Returns the number (1.. 366) of the day on which day/month/year falls
int dayNumber = (month - 1) * 31 + day;
if (month > 2) {
dayNumber = dayNumber - ((4 * month + 23) / 10);
if (isLeapYear(year)) dayNumber++;
}
return dayNumber;
} // dayInYear
with
public static boolean isLeapYear(int year)
{
return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
}
When I put it into a program it compiles but does not give the right answer I did desk check and the problem is in the dayInYear method
For example:February 5 2009 should yield 36 but I get 122
Any insight to correct method is appreciated...