1

Intro to JAVA please see below thank you! ----------------------------------------------------------------------------------------------- In the following program, declare an integer...

Question

Intro to JAVA please see below thank you! ----------------------------------------------------------------------------------------------- In the following program, declare an integer...

Intro to JAVA please see below thank you!

-----------------------------------------------------------------------------------------------

In the following program, declare an integer array daysInMonth that stores the number of days in January, February, March, April, and so on. Fill it with the appropriate values (31, 28, 31, 30, ...).

The program reads a month and year from the user.

When the year is a leap year, change the entry for February to 29.

Print out how many days the given month has.

CODE:

import java.util.Scanner;

public class NumberOfDays
{
   public static void main(String[] args)
   {
      // Declare and initialize daysOfMonth
      . . . daysOfMonth = . . .

      Scanner in = new Scanner(System.in);
      System.out.print("Month (1 - 12): ");
      int month = in.nextInt();
      System.out.print("Year: ");
      int year = in.nextInt();
    
      if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
         // It's a leap year. Adjust the entry for February
         . . .
      }

      // Get the number of days in the given month
      int days = daysOfMonth[. . .];

      System.out.println("Number of days: " + days);             
   }
}

Answers

Program:

package sample;

import java.util.Scanner;

public class NumberOfDays

{

public static void main(String[] args)

{

// Declare and initialize daysOfMonth

int daysOfMonth[] = {31,28,31,30,31,30,31,31,30,31,30,31};

Scanner in = new Scanner(System.in);

System.out.print("Month (1 - 12): ");

int month = in.nextInt();

System.out.print("Year: ");

int year = in.nextInt();

  

if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {

// It's a leap year. Adjust the entry for February

daysOfMonth[1]=29;//Here array index starts from 0 thats why seting 1st index to 29

}

// Get the number of days in the given month

int days = daysOfMonth[month-1];//same hoolds here

System.out.println("Number of days: " + days);

}

}

Output:


Similar Solved Questions

1 answers
1) An increase in the size of a body part or the organism is a. Usually...
1) An increase in the size of a body part or the organism is a. Usually accomplished by increasing the number of cells b. Can be caused by an increase in the size of cells c. Occurs because constructive activities occur at a faster rate than destructive ones d. All of the above e. None of the above ...
1 answers
< Chapter 8 HW Problem 8.70 - Enhanced - with Feedback < 12 of 15 >...
< Chapter 8 HW Problem 8.70 - Enhanced - with Feedback < 12 of 15 > Using bond enthalpies in the table, estimate Al for the following gas-phase reactions. un Review | Constants Periodic Table Part A Estimate AH for the reaction. Br-c-H+CI-C1B -C-CI+H-CI 463 146 190 203 234 Express your answ...
1 answers
A slide projector uses a thin lens with a focal length 132 mm to project a...
A slide projector uses a thin lens with a focal length 132 mm to project a clear image on a screen located 10.5 m from the lens. Calculate the distance the slide is from the lens and the magnification obtained. O 513 mm, m = -20.5 O 134 mm, m = -78.4 154 mm, m =-54.9 O 513 mm, m = 20.5 O 585 mm, m =...
1 answers
Consider the market for bolts. Imagine that a hardware factory dumps toxic waste into a nearby...
Consider the market for bolts. Imagine that a hardware factory dumps toxic waste into a nearby river, creating a negative externality for those lving downstrcam from the factory. Producing an additlonal tonne of bolts imposes a constant extermal cost of $105 per tonne. The following graph shows the ...
1 answers
A research center conducts an extensive survey consisting of an interview and medical examination with a...
A research center conducts an extensive survey consisting of an interview and medical examination with a representative sample of about 5000 people a year. The interview includes demographic, socioeconomic, dietary, and other health-related questions. The examination consists of medical, dental, and...
1 answers
Chapter 21 Electric Field Exercise 21.27- Enhanced-with Solution Part A What must the charge (sign and...
Chapter 21 Electric Field Exercise 21.27- Enhanced-with Solution Part A What must the charge (sign and magnitude) of a 1.47-g particle be for it to remain stationary when You may want to review (Page) For related problem-solving tips and strategies, you may want to view a Video Tutor placed in a dow...
1 answers
T-tests... evaluate the difference between exactly two means evaluate the difference between at least two means...
T-tests... evaluate the difference between exactly two means evaluate the difference between at least two means evaluate the bivariate relationship between two variables none of these...
1 answers
10.2 Series: Problem 1 Previous Problem Problem List Next Problem (1 point) Calculate S3, S4, and...
10.2 Series: Problem 1 Previous Problem Problem List Next Problem (1 point) Calculate S3, S4, and S, and then find the sum for the telescoping series s + 1) S₂ = 114 SA = 1/4 S5 = 1/4 S = 1/5...
1 answers
A candle is placed 14.7 cm in front of a convex mirror. When the convex mirror...
A candle is placed 14.7 cm in front of a convex mirror. When the convex mirror is replaced with a plane mirror, the image moves 7.0 cm farther away from the mirror. Find the focal length of the convex mirror....
1 answers
Complete the passage below, selecting the appropriate words from the list below.                              
Complete the passage below, selecting the appropriate words from the list below.                                     &nb...
1 answers
Sample of a gas in a cylindrical chamber with a movable piston occupied a volume of...
sample of a gas in a cylindrical chamber with a movable piston occupied a volume of 6.414 liters when the pressure was 850 torr and the temperature was 27.2 C. The pressure was readjusted to 4423 torr by moving the piston. What was the volume occupied by the sample under the new conditions if the te...
1 answers
TOVIUUSI IUDICII IUDICII LISL NCALI IUDICII (1 point) Find the first four terms of the Taylor...
TOVIUUSI IUDICII IUDICII LISL NCALI IUDICII (1 point) Find the first four terms of the Taylor series for the function cos(x) about the point a = 1/4. (Your answers should include the variable x when appropriate.) degree 0 term = 1/(2^(1/2)) degree 1 term = degree 2 term = degree 3 term = Note: You c...
1 answers
10 Page 4 of 10 Question 4 (1 point) A home improvement loan is to be...
10 Page 4 of 10 Question 4 (1 point) A home improvement loan is to be repaid by equal monthly payments for six years. The interest rate is 5.4% compounded monthly and the amount borrowed is $33,500. How much interest will be included in the first payment? Question 4 of 10 | Page 4 of 10 Question 4 (...
1 answers
A) Evaluate the surface integral Where , , B) Find the equation of the plane tangent...
A) Evaluate the surface integral Where , , B) Find the equation of the plane tangent to the surface at the point on the surface. Express the plane in standard form We were unable to transcribe this imageSir(u, v) = 5cosui + 5sinuj + uk VI VI Ο Κυ r(u, v) = ui + 3vj + u&r...
1 answers
How do you find the area of the triangle given A= 50 degrees, b= 12, c=14?
How do you find the area of the triangle given A= 50 degrees, b= 12, c=14?...
1 answers
As The New York Times reported, “Every day, on average, a scientific paper is retracted because...
As The New York Times reported, “Every day, on average, a scientific paper is retracted because of misconduct.” Two percent of scientists are willing to admit that they have manipulated their data to suit their purposes. Considering that researchers publish about 2 million articles each ...
1 answers
Use the following data to calculate the cost of goods sold: Work in process, beg. $38,000...
Use the following data to calculate the cost of goods sold: Work in process, beg. $38,000 Work in process, end.......... 31,000 Finished goods, beg............ 40,000 Finished goods, end.. 45,000 Cost of materials used.......... Direct labor costs.. Factory overhead.. 52,000 37,000 41,000 132,000 13...
1 answers
Implement a function that returns true if a String is Palindrome or false otherwise. A Palindrome...
Implement a function that returns true if a String is Palindrome or false otherwise. A Palindrome is a String that reads from right and left the same. An empty String, and a String with one character are Palindrome. public static boolean isPalindrome (String str) {...
1 answers
1. A runner dashes from the starting line (x0) to a point 98 m away and...
1. A runner dashes from the starting line (x0) to a point 98 m away and then turns around and runs to a point I19 m away from the starting point in 21 seconds. To the nearest tenth of a mis what is the average speed? 2. What is the runner's average velocity in the previous problem? 3. A car acce...

-- 0.042305--