Answer:
Following are the code to this question:
import java.util.*;//import package for user input
public class Exercise04_17 //defining class Exercise04_17
{
public static void main(String[] as)//defining the main method
{
int y,d=0; //defining integer variable
String m;//defining String variable
Scanner oxc=new Scanner(System.in);//creating scanner class object oxc
System.out.print("Enter a year: ");//print message
y=oxc.nextInt();//input year value which store in y variable
System.out.print("Enter a month: ");//print message
m=oxc.next();//input month value which store in m variable
if(m.equals("Jan")||m.equals("Mar")||m.equals("May")||m.equals("Jul")||m.equals("Aug")||m.equals("Oct")||m.equals("Dec"))//defining if block to check Month value
{
d=31;//assign value in d variable
}
if(m.equals("Apr")||m.equals("Jun")||m.equals("Sep")||m.equals("Nov"))//definingif block to check month value
{
d=30;//assign value in d variable
}
if(m.equals("Feb"))//defining if block to check month value is Feb
{
if(y%4==0||y%400==0)//defining if blook to check leap year
{
d=29;//assign value in d variable
}
else//else block
{
d=28;//assign value in d variable
}
}
if(d!=0)//defining if block that check d variable value not equal to 0
{
System.out.println(m+" "+y+" has "+d+" days");//print inserted value with message
}
else//else block
{
System.out.println(m+" is not a correct month name");//print message
}
}
}
Output:
please find the attachment.
Explanation:
Description of the code: