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
HELPPPP MEEEE!!!!! ITS LIFE OR MUERTEEE
garri49 [273]

The author uses the text structure of compare and contrast to show multiple signals.

<h3>What is Text structures?</h3>

This is a term that connote the method used by authors to put together information in text.

Note that in the case above, The author uses the text structure of compare and contrast to show multiple signals.

Learn more about text structure from

brainly.com/question/12053427

#SPJ1

8 0
1 year ago
What would be a good hash code for a vehicle identification that is a string of numbers and letters of the form “9x9xx99x9xx9999
Hunter-Best [27]
I also want to ask a question recently i used a software named [url=http://www.videoconverterfactory.com/tips/youtube-to-flac.html]youtube to flac[/url] while after the conversion the size is to big. Why did this happen and how to solve without lose quality?
4 0
3 years ago
witch option in a presentation program contains the formatting and placeholders for all the items that appear on a slide?
Nikitich [7]

SWITCH BETWEEN OPEN PRESENTATIONS. ..... Presentation software is a program designed for the production and display of .... image file format and version number. 1. .... Option. To Do This. Normal. Contains three panes: the outline pane, the slide pane, and the notes pane. .... appear on every slide in a presentation.

7 0
3 years ago
Read 2 more answers
What job does a front-end developer perform?
alina1380 [7]

Answer:

They manage making websit/es beautiful. Basically how brainly is setup? The layout is nice? Front end developers are responsible for why webpages look pretty or nicely done. <em>fun fact, my dream job is a front end developer!</em>

5 0
2 years ago
Create a simple JavaScript calculator.
Gre4nikov [31]

Answer: edit out anything you dont need

<!DOCTYPE html>  

<html lang = "en">  

<head>  

<title> JavaScript Calculator </title>  

 

<style>  

h1 {  

   text-align: center;  

   padding: 23px;  

   background-color: skyblue;  

   color: white;  

   }  

 

#clear{  

width: 270px;  

border: 3px solid gray;  

   border-radius: 3px;  

   padding: 20px;  

   background-color: red;  

}  

 

.formstyle  

{  

width: 300px;  

height: 530px;  

margin: auto;  

border: 3px solid skyblue;  

border-radius: 5px;  

padding: 20px;  

}  

 

 

 

input  

{  

width: 20px;  

background-color: green;  

color: white;  

border: 3px solid gray;  

   border-radius: 5px;  

   padding: 26px;  

   margin: 5px;  

   font-size: 15px;  

}  

 

 

#calc{  

width: 250px;  

border: 5px solid black;  

   border-radius: 3px;  

   padding: 20px;  

   margin: auto;  

}  

 

</style>  

 

</head>  

<body>  

<h1> Calculator Program in JavaScript </h1>  

<div class= "formstyle">  

<form name = "form1">  

     

   <!-- This input box shows the button pressed by the user in calculator. -->  

 <input id = "calc" type ="text" name = "answer"> <br> <br>  

 <!-- Display the calculator button on the screen. -->  

 <!-- onclick() function display the number prsses by the user. -->  

 <input type = "button" value = "1" onclick = "form1.answer.value += '1' ">  

 <input type = "button" value = "2" onclick = "form1.answer.value += '2' ">  

 <input type = "button" value = "3" onclick = "form1.answer.value += '3' ">  

  <input type = "button" value = "+" onclick = "form1.answer.value += '+' ">  

 <br> <br>  

   

 <input type = "button" value = "4" onclick = "form1.answer.value += '4' ">  

 <input type = "button" value = "5" onclick = "form1.answer.value += '5' ">  

 <input type = "button" value = "6" onclick = "form1.answer.value += '6' ">  

 <input type = "button" value = "-" onclick = "form1.answer.value += '-' ">  

 <br> <br>  

   

 <input type = "button" value = "7" onclick = "form1.answer.value += '7' ">  

 <input type = "button" value = "8" onclick = "form1.answer.value += '8' ">  

 <input type = "button" value = "9" onclick = "form1.answer.value += '9' ">  

 <input type = "button" value = "*" onclick = "form1.answer.value += '*' ">  

 <br> <br>  

   

   

 <input type = "button" value = "/" onclick = "form1.answer.value += '/' ">  

 <input type = "button" value = "0" onclick = "form1.answer.value += '0' ">  

   <input type = "button" value = "." onclick = "form1.answer.value += '.' ">  

   <!-- When we click on the '=' button, the onclick() shows the sum results on the calculator screen. -->  

 <input type = "button" value = "=" onclick = "form1.answer.value = eval(form1.answer.value) ">  

 <br>  

 <!-- Display the Cancel button and erase all data entered by the user. -->  

 <input type = "button" value = "Clear All" onclick = "form1.answer.value = ' ' " id= "clear" >  

 <br>  

   

</form>  

</div>  

</body>  

</html>  

Explanation:

3 0
2 years ago
Other questions:
  • An ethernet switch has a ____ table which is updated by ______.
    14·1 answer
  • When a Python script is running as a standalone program, what will the __name__ variable be set to?
    7·1 answer
  • g Q 2 Suppose I need a data structure having the following characteristics: a) must be very space efficient, and b) I have a goo
    6·1 answer
  • Count positive and negative number and compute the average. The program will have the user input an unspecified number of intege
    6·1 answer
  • Imagine that you have a friend who has expressed interest in designing and programming video games. He loves to play video games
    10·1 answer
  • Which of the following is not true about VOIP?
    9·1 answer
  • When proposing a plan in detail for video production phases, fundraising, and outreaching, which section will you use to make su
    14·2 answers
  • How do you mark the brainiest?
    8·2 answers
  • What does mean in computer science
    10·1 answer
  • What technology does kroger’s edge technology and amazon’s just walk out technology leverage?.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!