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
Taking phrases, sentences, or paragraphs of text from a source then using them without giving attribution is plagiarism. This in
lys-0071 [83]

Answer:

True, that would be plagiarism

8 0
2 years ago
Many people in the United States will say that they have rights, however, the majority of those people do not know what those ri
8090 [49]

Answer:

I think this answer would be...

Three of the rights guaranteed by the bill of rights would be freedom of speech, freedom of religion, and the right to bear arms. Freedom of speech lets me say what I need to or what but there are consequences to what I say. Freedom of religion allows me to practice any religion in the united states without it being illegal. The right to bear arms allows me to own a gun to hunt or protect myself when needed with a license or orange card.

3 0
2 years ago
Read 2 more answers
Which one of the following is considered a peripheral? A Software B Mouse C USB connector D Motherboard
Bogdan [553]

A mouse is considered that out of the options listed.

5 0
3 years ago
Read 2 more answers
Describe at least three of the characteristics that project managers look for in project participants and explain why you think
Vera_Pavlovna [14]

Answer:

1. Knowledge of Project Management Principles: A project participant should have the required knowledge of how project management works and how to function well in a team to achieve a common goal.

2. Time management skills: Despite the fact that it might be teamwork, the effectiveness of each individual is key. Every team member should be able to meet deadlines so as not to burden the team when they are given an individual task.

3. Excellent Communicator: A project participant should be able to communicate well with other team members, the project manager, different audiences, even customers and potential customers. Any weakness in communication skills could affect the project generally.

<u>why you think they are important</u>

1. Having knowledge of project management principles would lessen work and save time for the project manager and other team members as the project participant would have an idea per time of what to do.

2. A project participant that can manage time would generally increase the efficiency of the company, help the company meet deadlines, help the team meet targets.

3. Any weakness in communication skills could affect the project generally.

6 0
3 years ago
Which of these is mostly likely to help a teen have healthy online behavior
Damm [24]
What are the choices
8 0
3 years ago
Other questions:
  • Programming Using OOJAVA<br> check this Atterchment and solve Exascies 1, 2, and 3
    10·1 answer
  • What are two constraints that continuous-media files have that conventional data files generally do not have?
    12·1 answer
  • Which of the following devices are least likely to deny a connection inline when an attack is detected? (select 2)
    6·1 answer
  • The font color grid is located in the color group on the design tab. (points : 2) true false
    9·1 answer
  • Which of the following actions is an example of "window dressing?" a. Using some of the firm’s cash to reduce long-term debt. b.
    13·1 answer
  • Which of the four control methods is best suited for transfer of large blocks of data?
    8·1 answer
  • How to cancel branly subscription??​
    8·1 answer
  • Match the image to the view type in a presentation program. scroll bar tool bar status bar menu bar provides an array of buttons
    10·2 answers
  • HELP PLEASE!!!! Which type of prototyping is most often associated with the rapid prototyping development method?
    11·1 answer
  • Question 1
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!