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
Consider the following scenario below and recommend a solution.
sammy [17]

your account has enabled profile pictures for your users, you can manage all profile pictures for your account. Profile pictures are public and automatically approved when users upload an image in their settings. Using profile pictures can make it easier to see the users in your account and managing them gives you the ability to keep the pictures appropriate.

If Gravatars are enabled for an institution in account settings, and a user has a Gravatar but chooses not to upload a profile picture, the Gravatar will display for the user's profile picture.

If a student views another student's user details in a course and reports a profile picture as inappropriate, you can review those profile pictures and approve, lock, or delete the picture. In the courses, instructors can remove profile pictures completely from a user's details page.

5 0
2 years ago
Uses of keyboard as a input device
KATRIN_1 [288]

helps us for typing letters, numbers and symbols etc.

3 0
3 years ago
Read 2 more answers
What type of software resides on a computer’s hard drive, and controls the CPU and all other activity between components?
myrzilka [38]
Operating System  (OS) is the answer.

An application runs in/on an OS.  It is not the OS itself. Like Word or Chrome are applications. 

Systems is too generic and not specific enough to mean anything in this context.  Throw away answer.

Network Operating System does not 'usually' run on a hard drive but on memory chips in things like routers, wireless access points and switches that move network traffic.


3 0
3 years ago
On a printed circuit board, electronic components will be mounted from the
Likurg_2 [28]
On a printed circuit board, electronic parts will be mounted from the substrate side of the board. The leads jab through the substrate and the copper sheeting that has been carved. The leads are then soldered to the copper.

I hope the answer will help you. 
3 0
2 years ago
There are two algorithms called Alg1 and Alg2 for a problem of size n. Alg1 runs in n2 microseconds and Alg2 runs in 100n log n
nataly862011 [7]

The answer & explanation for this question is given in the attachment below.

8 0
3 years ago
Other questions:
  • A table with a width set to 600 pixels will look ________ on a monitor with resolution set to 640 × 480 than on a monitor with r
    10·1 answer
  • Stefan is finalizing his presentation by adding media files and preparing it for distribution. Stefan knows that saving a presen
    13·1 answer
  • Write the percentage 5 1/4 as a decimal​
    8·1 answer
  • Determine the exact output of the code $str = "The quick brown fox jumps over the the lazy dog"; echo strpos($str, 'fox');
    6·1 answer
  • Which threading model is best for achieving true parallelism and how?
    8·1 answer
  • The pay of an hourly worker is calculated by multiplying the hours worked by the hourly rate—up to 40 hours; any hours worked be
    11·1 answer
  • Johnathan was assigned to complete a project with three other people. What benefit will he get from working with the team?
    15·1 answer
  • What is the first thing animators need to determine when beginning a project?
    5·1 answer
  • 20 POINTS!!! I NEED HELPP
    6·2 answers
  • When constructing policies regarding data _______________, it is important that these policies offer particular guidance on sepa
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!