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]
2 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]2 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
Bluetooth is a common wireless protocol used to make pan connections. <br> a. True <br> b. False
Minchanka [31]
 a. True  This  is because it covers only a short distance  and allows  sharing of data between short distances(PAN) 
5 0
3 years ago
In a spreadsheet, equations that use addition, subtraction, multiplication, and division operators, as well as values and cell r
timama [110]

The equations that uses addition, subtraction, multiplication and division operators and other values in a spread sheet is known as formulas. They are a way of having to provide symbols in means of expressing information regarding a mathematical formula that are being solved or showing its solution along with it.

4 0
3 years ago
Get ready to be the Quizmaster! You are going to design your own Python game show in the style of a quiz.
marin [14]

Answer:

"Are apples Magenta?"\n(a) yes\n(b) sometimes\n (c) no\n\n",

"Are apples Teal?"\n(a) yes\n(b) sometimes\n (c) no\n\n",

"Are apples Gray?"\n(a) yes\n(b) sometimes\n (c) no\n\n",

"Are apples Green?"\n(a) yes\n(b) sometimes\n (c) no\n\n",

"Are apples Cyan?"\n(a) yes\n(b) sometimes\n (c) no\n\n",

]

Questions(Question prompts[0], "a")

Questions(Question prompts[1], "c")

Questions(Question prompts[2], "c")

Questions(Question prompts[3], "c")

Questions(Question prompts[4], "c")

Questions(Question prompts[5], "b")

Questions(Question prompts[6], "c")

Questions(Question prompts[7], "c")

Questions(Question prompts[8], "a")

Questions(Question prompts[9], "c")

Explanation:

6 0
2 years ago
¿Como explicarian que es un programa y la diferencia con el concepto de software y aplicacion.
Alina [70]

Answer:

Un programa de computadora es un conjunto de instrucciones que una computadora puede entender, escrito en un lenguaje de programación específico, en el caso de lenguajes de bajo nivel también en una arquitectura de computadora específica. En la mayoría de los casos, los programas se compilan en un formato que la computadora puede entender. A su vez, el conjunto de programas de una computadora es denominado software, mientras que una aplicación es un tipo específico de programa informático, especialmente utilizado en teléfonos móviles.

6 0
2 years ago
A technician from your isp has arrived to help you troubleshoot a weak wan connection. To what location do you take her?
stiv31 [10]

The answer is an Entrance Facility.

The entrance room or entrance facility is the location for the access provider equipment and demarcation points. This is the area of a building where carrier and private network enter the building. Whenever we talk about a WAN connection, we are talking about a geographically distributed private network that interconnects multiple LANs. Therefore, it is safe to say that you should take the technician to the entrance facility since it is the point at which the outdoor plant cable (WAN) connects with the building’s backbone cable (LAN).

8 0
2 years ago
Other questions:
  • Trading your bicycle for a snowboard exemplifies ?
    15·1 answer
  • Assume you have a project with seven activities labeled A-G (following). Derive the earliest completion time (or early finish-EF
    15·1 answer
  • A/an ___________ is a scheduling tool that sets the standard and nonworking time for the project and is used to assess how tasks
    6·1 answer
  • In this context, the word “session” refers to _____.
    5·2 answers
  • When was internet started in which year​
    13·2 answers
  • The game often becomes stuck on landscape mode when tilting the device during gameplay, which cuts off some peripheral text. A w
    8·1 answer
  • The ______ printers are the most popular type of printer in small office/home office and large office environments.
    5·1 answer
  • __________ is a broad class of software that is surreptitiously installed on a user's machine to intercept the interaction betwe
    6·1 answer
  • Why are pirated software considered a threat?​
    6·1 answer
  • Write a recursive function called digit_count() that takes a positive integer as a parameter and returns the number of digits in
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!