I need to be able to input two numbers, corresponding to a month and year, and have it return the number of days in that month. It all works except for when it gets to february and whether its a leap year or not. Currently it outputs 29, no matter what the year. I think it's something to do with the way the if and else statements are contained in each other, but not sure. Only recently started learning java so. Perhaps someone could give me a hand...
The isACenturyYear(year) and isDivisibleBy(year,400) are working methods already set above.
public int daysInMonth(int month, int year) { int daysInMonth ; daysInMonth = 0 ; boolean leap ; leap = false ; if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { daysInMonth = 31 ; } else { if (month == 4 || month == 6 || month == 9 || month == 11) { daysInMonth = 30 ; } else { if(isACenturyYear(year) || month == 2) { leap = isDivisibleBy(year,400) ; } else { leap = isDivisibleBy(year,4) ; } daysInMonth = 29 ; if (isACenturyYear(year) || month == 2) { leap =! isDivisibleBy(year,400) ; } else { leap =! isDivisibleBy(year,4) ; } daysInMonth = 28 ; } } return daysInMonth ; }