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
The conflict between the user's goal for unfettered access to data and the security administrator's goal to protect that data is
rewona [7]

Answer: Access control

Explanation:Access control is the type of security facility that is provided to the systems in an organization. The functions carried out in maintaining the security of the system is done by authenticating , authorizing and identification of the users and related components . They are secured using the PINs , passwords, bio-metric scan etc.

The situation of the user wanting to have a unrestrained access towards data as well as maintaining the security is the done by access control.

8 0
2 years ago
Read 2 more answers
The correct or acceptable way of communicating on the internet is known as
stepladder [879]
I want to say e-mail.

8 0
3 years ago
A stored program computer is designed to compute precisely one computation, such as a square root, or the trajectory of a missil
mr Goodwill [35]

Answer: False

Explanation:

 The given statement is false as, a stored program computer is one of the type of computer system which storing the program instruction in the form of electronic memory.

  • It perform different types of tasks in the sequence and it also enables the digital computer system more effective and flexible.
  • In this stored program computer the program instructions are get stored on the plugboards.

Therefore, the given statement is false.

4 0
3 years ago
wo non-negative integers x and y are equal if either: Both are 0, or x-1 and y-1 are equal Write a function named equals that re
Mrac [35]

Answer:

Using python programming language.

Explanation:

#to define the function write as below

def equal():

    #to get the two integers from the user

#The user is asked for input in the code below.

x = int(input("Enter the value for X"))

y= int(input("Enter the value for y"))

if x==0 and y==0:

    print("both numbers are ", "0")

elif: x==1 and y==1:  #This test if both x and y are 1

    print("true")

elif: x==y: #this line test if both values are equal

    print("true")

else:

    print("False")

equal()  #end of the function

3 0
3 years ago
"3. 4. Simple number search We will pass you 2 inputs an list of numbers a number, N, to look for Your job is to loop through th
Arisa [49]

Answer:

Following is given the detailed solution to the question given.

  • First image contains source code. All the steps are described with help of comments.
  • Second image contains the output or the program given.

I hope it will help you!

Explanation:

4 0
3 years ago
Other questions:
  • Which type of architecture places a firewall in front of the VPN to protect it from Internet-based attacks as well as behind a f
    6·1 answer
  • (I'LL GIVE BRAINLIST)
    10·2 answers
  • Why is Abraham called the Father of Believers?
    6·1 answer
  • As the network engineer, you are asked to design an IP subnet plan that calls for three subnets. The largest subnet needs a mini
    14·1 answer
  • How are logical operators used?
    14·1 answer
  • What's the best strategy for avoiding ATM fe
    14·1 answer
  • High level language - An object oriented programming language​
    5·1 answer
  • When creating any digital work, what is the MOST important thing to remember?
    7·1 answer
  • Which is an example of a demand account
    10·1 answer
  • Fifteen years ago, everyone didn't have a cell phone. Anyone developing an app would not have found many users. Today, the exist
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!