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 happens if you move unencrypted files into an encrypted folder?
mr_godi [17]
The new files become encrypted
6 0
3 years ago
Which adaptation of eap utilizes eap-mschapv2 inside of an encrypted tls tunnel?
cluponka [151]

Main Answer:

<h3>which adaptation of eap utilizes eap mschapv2 inside of an encrypted tls tunnel? <u>protected (EAP)</u></h3>

sub heading:

what is meant by protected( EAP)?

Explanation:

1.The protected extensible authentication protocal also known as protected (EAP).

2.transport layer security tunnen

Refference link :

https//brainly.com

Hashtag:

#SPJ4

7 0
2 years ago
Exposing employee and customer personal data to an untrusted environment is an example of:
jonny [76]

Answer:

data breach

Explanation:

A data breach is a security event in which a unauthorized person steals, copy, access or transfer personal or confidential data. A data breach is the deliberate or unintentional leak of sensitive data into an distrusted environment. When a perpetrator or cyber criminal effectively invades a data source and steals confidential information, a data breach happens. This can be achieved physically by manipulating a device or network to steal or hack local data. Data breach is being used to target companies mostly by remotely bypassing network security.Data breaches include financial and personal information, trade secrets of companies or intellectual property, files, confidential documents etc.

8 0
3 years ago
A network is a group of two or more computers that are connected to share resources and information. T or f
Ulleksa [173]

Answer:

true

Explanation:

5 0
3 years ago
Read 2 more answers
What careers are most likely to require business skills
olchik [2.2K]

i would say maybe an accountant, entrepreneur, business reporter, or something like that.

8 0
3 years ago
Other questions:
  • after turning the volume all the way up on the speakers, you still cannot hear any sound. which of the following should be your
    9·1 answer
  • PLEASE HELP ASAP!! WILL MARK BRAINLIEST!! 20 POINTS!!
    6·1 answer
  • The functions of forums
    15·1 answer
  • Someone claims that the big O notation does not make sense at all, and they give the following example. An algorithm A that proc
    15·1 answer
  • As a digital investigator for your local sheriff’s department, you have been asked to go with a detective to a local school that
    13·1 answer
  • Cómo surge y cuál es el objetivo del observatorio de radio y televisión
    11·1 answer
  • Why is it important to prevent financial loss
    7·1 answer
  • What is the full form of SAARC<br><br>And free point!! ​
    15·2 answers
  • True or false: Quality score is an algorithm that scores each of your search ads on spelling and grammar.
    10·1 answer
  • Which of the following BEST describes a permissive software license?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!