For my Comp Sci class I have to make a program that finds the number of days in the given month(1-12), do ya'll know why I'm getting the error "variable days might not have been initialized" when trying to return the int "days" from the switch? Here's the code:
public static int getNumberofDays(int month,int year)
{
// Imports the required Scanner
Scanner kbd = new Scanner(System.in);
final String month;
final int days;
switch (month) {
case 1: days = 31;
break;
case 2: if ((year % 4 == 0) && year % 100 != 0)
{
days = 29;
}
else if ((year % 4 == 0) && (year % 100 == 0) && (year % 400 == 0))
{
days = 29;
}
else
{
days = 28;
}
break;
case 3: days = 31;
break;
case 4: days = 30;
break;
case 5: days = 30;
break;
case 6: days = 31;
break;
case 7: days = 31;
break;
case 8: days = 31;
break;
case 9: days = 30;
break;
case 10: days = 31;
break;
case 11: days = 30;
break;
case 12: days = 31;
break;
default: month = "invalid";
break;
}
return days;
}