Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Test plan for import java.util.Scanner; public class Exercise 0 3 _ 1 1 { public static void main ( String [ ] args ) {

Test plan for import java.util.Scanner;
public class Exercise03_11
{
public static void main(String[] args)
{
//Declare variables
String month="";
int days=0;
Scanner s=new Scanner(System.in);
// Read the month number from user
System.out.print("Enter a month in the year (e.g.,1 for Jan): ");
int month_number=s.nextInt();
// Read the year from user
System.out.print("Enter a year: ");
int year=s.nextInt();
// Check the month number and assign month name and
// number days
if(month_number==1)
{
month="January";
days=31;
}
else if(month_number==2)
{
month="February";
// Check the leap year conditions
if((year%400==0) && (year%100==0))
{
days=29;
}
else if((year%4==0) && (year%100!=0))
{
days=29;
}
else
{
days=28;
}
}
else if(month_number==3)
{
month="March";
days=31;
}
else if(month_number==4)
{
month="April";
days=30;
}
else if(month_number==5)
{
month="May";
days=31;
}
else if(month_number==6)
{
month="June";
days=30;
}
else if(month_number==7)
{
month="July";
days=31;
}
else if(month_number==8)
{
month="August";
days=31;
}
else if(month_number==9)
{
month="September";
days=30;
}
else if(month_number==10)
{
month="October";
days=31;
}
else if(month_number==11)
{
month="November";
days=30;
}
else if(month_number==12)
{
month="December";
days=31;
}
// Print the output
System.out.println(month+""+year+" has "+days+" days");
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions