1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
pshichka [43]
3 years ago
13

Write a program that prompts the user to enter the month and year and displays the number of days in the month. For example, if

the user entered month 2 and year 2000, the program should display that February 2000 has 29 days. If the user entered month 3 and year 2005, the program should display that March 2005 has 31 days.Here is a sample run of this program:Enter a month in the year (e.g., 1 for Jan): 1Enter a year: 2009January 2009 has 31 daysExercise 3.11Liang, Y. Daniel. Introduction to Java Programming (8th Edition)
Computers and Technology
1 answer:
valentinak56 [21]3 years ago
3 0

Answer:

Following are the program in JAVA language  

import java.util.Scanner; // import package

import java.util.Calendar; // import package

public class Main // class main  

{  

public static void main(String[] args) // main function  

{  

Scanner input = new Scanner(System.in); // for user input  

Calendar calendar = Calendar.getInstance(); //get calendar instance for methods  

int nYear , nMonth , date =1 , nDays;

String MonthOfName = "";

 System.out.print(" Enter a month in the year :");

 nMonth = input.nextInt(); //input Month

 System.out.print("Enter a year :");

 nYear = input.nextInt(); //Input Year

 switch (nMonth) //Find month name via 1-12

 {

  case 1:

MonthOfName = "January";

nMonth = Calendar.JANUARY;

break;

case 2:

MonthOfName = "February";

nMonth = Calendar.FEBRUARY;

break;

case 3:

 MonthOfName = "March";

nMonth = Calendar.MARCH;

break;

 case 4:

 MonthOfName = "April";

nMonth = Calendar.APRIL;

 break;

 case 5:

MonthOfName = "May";

nMonth = Calendar.MAY;

break;

case 6:

MonthOfName = "June";

nMonth = Calendar.JUNE;

break;

case 7:

 MonthOfName = "July";

nMonth = Calendar.JULY;

break;

 case 8:

MonthOfName = "August";

nMonth = Calendar.AUGUST;

break;

case 9:

MonthOfName = "September";

nMonth = Calendar.SEPTEMBER;

break;

case 10:

MonthOfName = "October";

nMonth = Calendar.OCTOBER;

break;

case 11:

 MonthOfName = "November";

nMonth = Calendar.NOVEMBER;

break;

case 12:

MonthOfName = "December";

nMonth =Calendar. DECEMBER;

         }        

 calendar.set(nYear, nMonth, date); // set date to calender to get days in month

nDays=calendar.getActualMaximum(Calendar.DAY_OF_MONTH); // get no of days in month

System.out.println(MonthOfName + " " + nYear + " has " + nDays + " days."); //print output

}

}

Output:

Enter a month in the year : : 09

Enter a year : 2019

September 2019 has 30 days.

Explanation:

In this program we have take two user input one for the  month and other for the year Also take two variables which are used for storing the month name and no of days in a month. with the help of switch we match  the cases  and store the month value .After that  set the date to calender with help of calendar.set(nYear, nMonth, date) method and  To get the number of days from a month  we use  calendar.getActualMaximum(Calendar.DAY_OF_MONTH);  method and finally print year and days.

 

     

You might be interested in
What is the first step to creating a PivotTable?
lara31 [8.8K]

Answer:

Click anywhere in the dataset

Go to Insert –> Tables –> Pivot Table.

In the Create Pivot Table dialog box, the default options work fine in most of the cases.

click ok

Explanation:

4 0
3 years ago
Read 2 more answers
Write the definition of a function named swapints that is passed two int reference parameters. The function returns nothing but
Alja [10]

Answer:

void swapints(int *j,int *k)//Function definition.

{

   *j=*j+*k-(*k=*j); //value swapping.

}

swapints(&j,&k);//call the function.

Explanation:

  • The above function definition takes the address of j and k variables which is stored on the pointer variable j and k.
  • Then the pointer variable uses the j and k value for the above expression, and the user does not need to return the value of j and k.
  • But when the user prints the value of the j and k variable, then he gets the swapping value of the j and k variable.
  • The user needs to know that the "int j" is a normal variable, but "int *j" is a pointer variable that is used to take the address of j variable.
3 0
3 years ago
Visit the online certified EHR directory at https://chpl.healthit.gov/ and click Browse all to search. Select a minimum of 3 ven
jok3333 [9.3K]

Answer:

3 Vendor - 24/7 smartEMR

Explanation:

2014 VIPA Health Solutions, LLC 24/7 smartEMR 6.0 May 8, 2014 , Practice Type Ambulatory.  Certification Criteria 42 met.

2014 VIPA Health Solutions, LLC 24/7 smartEMR 6.1 Apr 11, 2017, Practice Type Ambulatory.  Certification Criteria 45 met.

2015 VIPA Health Solutions, LLC 24/7 smartEMR 7.1 Mar 28, 2018,

Practice Type  N/A. Certification Criteria 47 met.

5 0
3 years ago
What is the output of the following program? #include using namespace std; class TestClass { public: TestClass(int x) { cout &lt
Lunna [17]

Answer:

The answer is "Hello!".

Explanation:

  • In the given C++ language program, a class "TestClass " is defined, which contains a parameterized constructor and default constructor.
  • In the parameterized constructor an integer variable "x" is passed in the constructor parameter and inside a constructor parameter value is print. Inside the default constructor, a print function (cout) is used that print message "Hello!".
  • In the main method, a class "TestClass" object is created that is "test" when a class object is created it automatically called a default constructor that's why the output to this code is "Hello!".

6 0
3 years ago
What must each computer that is part of the network have installed in order to connect it to the network?
Dominik [7]

No 
Network means Computer in Interconnection with each other. network is the need of organization or when we need Internet or search something then we connect other wise i mostly used without network when i write program. <span />
3 0
3 years ago
Other questions:
  • True or False? A supervisory control and data acquisition (SCADA) device is a computer that controls motors, valves, and other d
    13·1 answer
  • Which of these options would likely have a better playback experience in your presentation?
    8·2 answers
  • A computer has 9850 processes and 172 of them where suspended while 276 were terminated.,explain why some of the processes where
    15·1 answer
  • What is the traditional cognitive perspective ofHCL?
    12·1 answer
  • What are scientists going to explore next on Kepler-186f? A) evidence of the existence of life B) types of plant life that exist
    8·2 answers
  • Given that Apache and Internet Information Services (IIS) are the two most popular web application servers for Linux and Microso
    10·1 answer
  • What technology did one of the student's have to learn to use in order to help him with his homework in the film, "Disconnected:
    11·2 answers
  • Select the correct answer. Which sign or symbol will you use to lock cells for absolute cell reference?
    9·2 answers
  • Collisions occur when one output is mapped to two inputs. <br><br> A. True <br> B. False
    7·2 answers
  • Where else can the computer send the results of processing other than to output​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!