Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1
public class MonthDays {
public void main(int year, int month)
{ if (month < 1 || month > 12) { System.out.println("Invalid month. Please enter a value between 1 and 12."); } else { int days = getDaysInMonth(year, month); String monthName = getMonthName(month); System.out.println(monthName + " " + year + " has " + days + " days."); } } public int getDaysInMonth(int year, int month) { int[] daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int days = daysInMonth[month - 1]; if (month == 2 && isLeapYear(year)) { days = 29; } return days; } public boolean isLeapYear(int year)