First f all you could modify your code frompublic static int daysInMonth ( int month, int year )
{
int numberOfDays = 31;
switch (month)
{
case 2: // February
numberOfDays = 28;
if (year % 4 == 0)
{
numberOfDays = 29;
if ( year % 100 == 0 && year % 400 != 0 )
numberOfDays = 28;
}
break;
case 4: // April
case 6: // June
case 9: // September
case 11: // November
numberOfDays = 30;
break;
}
return numberOfDays;
}
/*
* This method returns
* the day of the week for a given date
*/
public static int dayOfTheWeek (int day, int month, int year) {
to smthg slightly more efficient :public static int daysInMonth ( int month, int year )
{
switch (month)
{
case 2: // February
if ( ( year % 4 == 0 )
& ( year % 100 != 0)
& ( year % 400 != 0 ) )
return 29;
retrun 28;
case 4: // April
case 6: // June
case 9: // September
case 11: // November
return 30;
default
retrun 31;
} // end of SWITCH
}
/*
* This method returns
* the day of the week for a given date
*/
public static int dayOfTheWeek (int day, int month, int year)
For getting the day of the week of what ever, I believe you should better give a look at java.util.GregorianCalendar...
Everything should be in it !
Unless you need to code it yourself !
Thomas SMETS,
SCJP2 - Brussels