I have to write a switch statement with a function called no_in_month,that outputs the number of days for any month.For example if the input is 1 is passed to this function the output is 31(month 1 has 31 days),if 2 is passed the output is 28 and so on.
(01-01-2010 05:55 AM)samezoobi Wrote: [ -> ]I have to write a switch statement with a function called no_in_month,that outputs the number of days for any month.For example if the input is 1 is passed to this function the output is 31(month 1 has 31 days),if 2 is passed the output is 28 and so on.
A quick solution would be to create a "look-up table".
// Look-up Table
int DAYS_IN_MONTH [12] = { 31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31 };
// Method
public int no_in_month( int month )
{
return DAYS_IN_MONTH[month-1];
}