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
Coment on this if your user starts with dida
ratelena [41]

Answer:

oh sorry i needed points but i have a friend whos user starts with dida

Explanation:

8 0
2 years ago
A set of programs that enable the hardware to process data is _____.
Mnenie [13.5K]
The most appropriate answer is C !! software os used for using hardware !!
4 0
3 years ago
What is the advantage of learning through story compared to learning through personal experience?
Inessa [10]

Answer:

Personal Experience

Explanation:

If a story is based on a personal experience then yes, the two doesn't matter. <em>However</em>, usually learning through personal experience is better because you learn firsthand while stories are written from a different perspective.

6 0
2 years ago
Read 2 more answers
[C++ for array week|
melamori03 [73]

Answer:

this is stupi

Explanation:

8 0
2 years ago
1. What is wrong with the following code?
uranmaximum [27]

Answer:

Aye dog I don't know nothing about code, yes its true, but I hope that you get an answer for you!

Explanation:

Facts...

5 0
3 years ago
Other questions:
  • Your game design company has recently asked all employees to use a specific personal information management application (PIM) to
    6·1 answer
  • What is the purpose of the overload keyword in the ip nat inside source list 1 pool nat_pool overload command?
    8·1 answer
  • The acceleration of a body is 3 metre per second square what does it mean​
    11·2 answers
  • Question 1 Multiple Choice Worth 5 points)
    10·1 answer
  • Select the guidelines you should follow when creating a resume
    12·2 answers
  • The electric company gives a discount on electricity based upon usage. The normal rate is $.60 per Kilowatt Hour (KWH). If the n
    7·1 answer
  • Software is the word for:
    15·1 answer
  • What is the ghosted text or picture behind the content on the page?​
    6·1 answer
  • What software application is most appropriate to use to create multimedia presentations?
    6·2 answers
  • How to send an email to multiple recipients individually outlook
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!