0% found this document useful (0 votes)
8 views

PROGRAM 13

Uploaded by

bruhanth2008
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

PROGRAM 13

Uploaded by

bruhanth2008
Copyright
© © All Rights Reserved
Available Formats
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)

{
boolean leap = false;
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
leap = true;
}
return leap;
}

public String getMonthName(int month) {


String[] months = {
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
String monthName = "";
for (int i = 0; i < months.length; i++) {
if (i == month - 1) {
monthName = months[i];
break;
}
}
return monthName;
}
}

You might also like