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
1. A(n) ____ is a special type of inline image in which you define one or more areas as hotspots. *
3241004551 [841]

<span>1.       </span>Image map

Typically, web pages use different types of inline images. An image map defines one or more areas as hotspots and is a special type of inline image. For instance, every hotspot in an image map is able to link to a different page.


<span>2.       </span>Headings

Once the Web page structure is set, you can now enter content of the web page informational text paragraphs and headings. Headings separate text or add new topics on the page. Headings are indicated by the tags <h1> all through to <h6>


<span>3.       </span>Deprecated tags

<span>By default, W3C supports 3 document types for XHTML HTML, frameset, transitional, and strict. Strict is specified when you want to illegalize use of deprecated tags. Deprecated tags are tags that W3C has earmarked for eventual removal from their specifications because these tags have been replaced by much more newer and functional tags.
</span>
<span />

<span>4.       </span>Frameset document type

As mentioned above in question 3, W3C supports 3 document types for XHTML HTML, frameset, transitional, and strict. Frameset document type is used to support frames on a page and allows the use of deprecated tags.


<span>5.       </span>Definition list

Definition list is an example of a list that offsets info in a dictionary like style. They are not often used as compared to unordered and ordered lists and are important in creating a glossary like list of definitions and items.

6.       Virus.

A virus is a malicious software code that multiplies and replicates by copying itself to another application, document, boot sector and changes how a computer should operate. Typically, a computer virus cannot reproduce without programming a document or a file.


<span>7.       </span>Width Attribute

This attribute specifies the width of an image and the height specifies the height of an image. Both are measured in pixels and the value must always be in pixel. It specifies the width of a cell attribute and is used to set a predefined width of a cell.


<span>8.       </span>Alt attribute

Commonly used with the <img> tag, the alt attribute specifies an alternate image or text, if the image is not in a position to be displayed. The required alt attribute provides info of an image if a user for known or unknown reasons cannot view it.


<span>9.       </span>Color property

It defines the text for an HTML element. It is specified by the color name, a HEX value and an RGB value. The most common ways amongst these three is the HEX value. You can also use color name by replacing the HEX code with the name of the color.


<span>10.       </span>Source Code

Source code is that HTML code which is translated into a graphical web page by a browser. It is possible to view the source code for any page from within the web browser. Using this feature,  it can help one check his or her own code or for another developer.











6 0
3 years ago
States that processing power for computers would double every two years
hodyreva [135]

Answer:

Moore's Law

Explanation:

4 0
2 years ago
How can I use the internet/social media to protect my identity?
sattari [20]
Don't show your face and don't put your name or location online? i'm confused by this question.
3 0
3 years ago
The rule of thumb in the wireless industry is that a smartphone uses 4 gigabytes of data per month where ____ percent travels th
lianna [129]
I believe the correct answer is 75%. <span>The rule of thumb in the wireless industry is that a smartphone uses 4 gigabytes of data per month where 75% percent travels through wi-fi or 3 gb travels through wi-fi. Hope this answers the question. Have a nice day.</span>
4 0
3 years ago
Read 2 more answers
A trust domain is defined as Select one: a. The agreed upon, trusted third party b. A scenario where one user needs to validate
soldier1979 [14.2K]

Answer:

A construct of systems, personnel, applications, protocols, technologies, and policies that work together to provide a certain level of protection

Explanation:

Creation of dynamic Trust Domains can be realized through collaborative, secure sharing solutions. The local system is able to trust a domain to authenticate users. If an application or a user is authenticated by a trusted domain, all domains accept the authenticating domain. For instance, if a system trust domain X, it will also trust all domains that domain X trusts. It is a two-way trust relationship and is transitive.

7 0
3 years ago
Read 2 more answers
Other questions:
  • What is the portion of the PowerPoint window that contains the current slide, total slides, zoom options, and various shortcuts
    8·1 answer
  • ________ means that IT capacity can be easily scaled up or down as needed,which essentially requires cloud computing. A) agility
    15·1 answer
  • To share a document in my online electronic journal, I should select the option to _____.
    14·1 answer
  • Which item is most likely to be a standard part?
    14·1 answer
  • 4.9 Code Practice: Question 3
    15·2 answers
  • Why is it important to perform routine computer maintenance? It can make more room for junk files and downloadable programs. It
    13·2 answers
  • Write a definition in your own words for GUI. Do not copy and paste please.
    8·2 answers
  • The most effective technique of malware propagation among the following list
    7·1 answer
  • Which XXX and YYY correctly output the smallest values? Vector user Vals contains integers (which may be positive or negative).
    15·1 answer
  • The best team in nba like right now
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!