Program to accept a year and month number from the user and print the corresponding number of days in the month including name of the month.
Java
import java.util.*;
public class MonthDays
{
public static void main(String args[])
{
int choice=0,year=0;
Scanner sc=new Scanner(System.in);
System.out.print("Enter year: ");
year=sc.nextInt();
System.out.print("Enter a month number: ");
choice=sc.nextInt();
switch(choice)
{
case 1:
{
System.out.print("January: 31 Days");
break;
}
case 2:
{
if (((year%4==0)&&(year%100!=0))||(year%400==0))
{
System.out.print("February: 29 Days");
}
else
{
System.out.print("February: 28 Days");
}
break;
}
case 3:
{
System.out.print("March: 31 Days");
break;
}
case 4:
{
System.out.print("April: 30 Days");
break;
}
case 5:
{
System.out.print("May: 31 Days");
break;
}
case 6:
{
System.out.print("June: 30 Days");
break;
}
case 7:
{
System.out.print("July: 31 Days");
break;
}
case 8:
{
System.out.print("August: 31 Days");
break;
}
case 9:
{
System.out.print("September: 30 Days");
break;
}
case 10:
{
System.out.print("October: 31 Days");
break;
}
case 11:
{
System.out.print("November: 30 Days");
break;
}
case 12:
{
System.out.print("December: 31 Days");
break;
}
default:
{
System.out.println("Month does not exist");
}
}
}
}Java