Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!