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
den301095 [7]
3 years ago
13

Write a program that reads in the following data, all entered on one line with at least one space separating them: a) an integer

representing a month b) an integer representing the day of the month c) an integer representing a year 1. Check that the month is between 1 and 12. If it’s not print an error message. 2. Day cannot be 0 or less nor can it be more than 31 for all months. Print an error message if these conditions occur. If day is in the range of 0 and 31, you will still need to check other conditions as noted below in 4. 3. Year cannot be less than 1. Print an error message if that occurs. If any one of these three conditions occurs, only one error message should print and no further code should be executed. If everything is good so far, then continue as below: 4. Check that day is correct for the month. Remember the poem "30 days has September, April, June and November, All the rest have 31 except February which has 28 but in a leap year has 29"
Computers and Technology
1 answer:
Rina8888 [55]3 years ago
4 0

Answer:

import java.util.Scanner;

public class DataConstraint {

public static void main(String[] args) {

System.out.print("Enter month, day, year separated by spaces :");

Scanner sc=new Scanner(System.in);

int M,D,Y;

M=sc.nextInt();

D=sc.nextInt();

Y=sc.nextInt();

if(1<=M && M<=12 && 1<=D && D<=31 && Y>=1)

{

if(M==4 || M==6 ||M==9 || M==11){

if(D==31) {

System.out.println("month "+M+" can not have more than 30 days");

System.exit(0);

}

}

else if(M==2)

{

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

if(D>=30) {

System.out.println("month "+M+" cannot have "+D+" days");

System.exit(0);

}

}

else {

if(D>=29) {

System.out.println(Y+" is not a leap year, "+D+" is invalid");

System.exit(0);

}

}

}

System.out.println(M+" "+D+" "+Y+" is a valid date");

}

else{

if(1>=M || M>=12) System.out.println(M+" is not a valid month");

if(1>=D || D>=31) System.out.println(D+" is not a valid date");

if(Y<1) System.out.println("year can not be negative");

}

}

}

Explanation:

  • Use a conditional statement to check the month is between 1 and 12.
  • Check that the date is between 1 and 31 and year must be positive value.
  • If no. of days are more than 29, then the year cannot be a leap year.

You might be interested in
What is the Digital Living Network Alliance ?
Sedaia [141]

The digital living alliance network is a set of guidelines to share digital media among wired and wireless multimedia devices.

<h3>What is the digital living alliance network?</h3>

The Digital Living Network Alliance is a trade association that establishes rules and practices for home network equipment, incorporating computers, smartphones, etc.

It is a set of guidelines to share digital media among wired and wireless multimedia devices.

Learn more about digital on:

brainly.com/question/23749502

#SPJ12

8 0
2 years ago
Read 2 more answers
How to keep tools and equipment safeuh​
ivanzaharov [21]

Answer:

Use pelican, or similar heavy duty cases

Explanation:

Pelican is a brand btw. 10/10 would recommend

8 0
3 years ago
Read 2 more answers
The _____ feature automatically corrects typing, spelling, capitalization, or grammar errors as you type them.
Snezhnost [94]
Autocorrect is the answer
6 0
3 years ago
For an activity with more than one immediate predecessor activity, which of the following is used to compute its earliest finish
laila [671]

Answer:

The correct option is A

Explanation:

In project management, earliest finish time for activity A refers to the earliest start time for succeeding activities such as B and C to start.

Assume that activities A and B comes before C, the earliest finish time for C can be arrived at by computing the earliest start-finish (critical path) of the activity with the largest EF.

That is, if two activities (A and B) come before activity C, one can estimate how long it's going to take to complete activity C if ones knows how long activity B will take (being the activity with the largest earliest finish time).

Cheers!

7 0
3 years ago
The events that happen in a story are called the _________________.
RUDIKE [14]

Answer: B) plot

Explanation:

4 0
2 years ago
Read 2 more answers
Other questions:
  • The ____ function displays the highest value in a range.
    15·2 answers
  • Sandie is writing a report for her environmental science class. She has asked her older sister who is away at college to proof h
    13·2 answers
  • What version of ubuntu is linux mint 17.3 based on?
    14·1 answer
  • What command would you use to list the text files in your
    7·1 answer
  • A _____ is a member function that is automatically called when a class object is created.
    13·1 answer
  • Page No.
    10·1 answer
  • How to bypass a Lightspeed and Rocket Filter blocked website without being a admin and without downloading extensions? Must incl
    15·1 answer
  • Write a Python program that inputs an integer between 0 and 1000 and adds all the digits in the integer. For example, if integer
    6·1 answer
  • What are some ways you can give staying off your phone a "boost" and make it easier to do?
    9·1 answer
  • Who invented Computer? Answer Differently​
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!