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
pochemuha
3 years ago
12

Write a program that reads a string from the keyboard and tests whether it contains a valid date. Display the date and a message

that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid. The input date will have the format mm/dd/yyyy. A valid month value mm must be from 1 to 12 (January is 1). The day value dd must be from 1 to a value that is appropriate for the given month. September, April, June, and November each have 30 days. February has 28 days except for leap years when it has 29. The remaining months all have 31 days each. A leap year is any year that is divisible by 4 but not divisible by 100 unless it is also divisible by 400.
Computers and Technology
1 answer:
Anna11 [10]3 years ago
6 0

Answer:

// here is code in java.

import java.util.*;

// class definition

public class Main {

   // main method of the class

   public static void main(String[] args) throws Exception {

       // Scanner object to read date

       Scanner in = new Scanner(System.in);

       System.out.print("Enter a date in format mm/dd/yyyy to check:");

       // read the date from user

       String inp_date = in .next();

       // split the date with "/" delimeter

       String[] ip = inp_date.split("/");

       // find month from date

       int inp_month = Integer.parseInt(ip[0]);

       // find day from date

       int inp_day = Integer.parseInt(ip[1]);

       // find year from date

       int inp_year = Integer.parseInt(ip[2]);

       // boolean variable

       boolean flag = true;

       // print the input date

       System.out.println("Your Entered date was: " + inp_date);

       

       // check month is valid or not

       if (inp_month < 1 || inp_month > 12)

       {

           

           System.out.println("Entered Date is invalid:");

           System.out.println("The input month  is not from 1 - 12.");

           flag = false;

           

       }

       //check day is valid or not

       else if (inp_day < 1) {

           

           System.out.println("Entered Date is invalid:");

           System.out.println("The value of day is less than 1.");

           flag = false;

       }

       // check days in those month which has 30 days

       else if ((inp_month == 4 || inp_month == 6 || inp_month == 9 || inp_month == 11) && inp_day > 30) {

           

           System.out.println("Entered Date is invalid::");

           System.out.println("This month have only 30 days, but Entered day is greater than 30.");

           flag = false;

           

       }

       // if month is February then check leap year and days

       else if (inp_month == 2 && ((inp_year % 4 == 0) && (inp_year % 100 != 0))) {

           if (inp_day > 29) {

               

               System.out.println("Entered Date is invalid::");

               System.out.println("In a leap year, only 29 days in February.");

               flag = false;

           

           }

       }

       // if month is February and year is non-leap

       else if (inp_month == 2 && inp_day > 28) {

           

           System.out.println("Entered Date is invalid:");

           System.out.println("In a non-leap year, only 28 days in February.");

           flag = false;

       }

       // if all are valid

       if (flag)

           System.out.println("Entered Date is valid:");

   }

}

Explanation:

Read the date from user in mm/dd/yyyy format with the help of Scanner object. Extract day, month and year from the date. Then check whether month is between 1-12 or not and print appropriate message. After that check day is less than 1 or not, if not then print reason. Check the days in those month which has 30 days in it.If month is February then check for leap year and day is greater than 29 then print reason. Else if month is February and year is non-leap then check days whether it is greater than 28 or not. In last If value of flag is true then print date is valid.

Output:

Enter a date in format mm/dd/yyyy to check:2/30/2012                                                                          

Your Entered date was: 2/30/2012                                                                                              

Entered Date is invalid::                                                                                                    

In a leap year, only 29 days in February.

You might be interested in
You want to connect to a user desktop to review windows 10 configuration settings when the user is not present. which technology
MakcuM [25]

Remote desktop is a technology that allows users to connect to a specific computer from a remote location as if they were sitting in front of it.

<h3>What is the desktop remote system?</h3>

A remote desktop is a program or an operating system feature that permits a user to connect to a computer in another location, see that computer's desktop and interact with it as if it were local.

<h3>What is Remote Desktop example?</h3>

A basic example of a Remote Desktop is securing your home laptop to your office PC so you can access files, run applications, print documents, etc. on that PC without going into the office.

However, the host machine does not have to be a PC. It is often a waitperson or virtual server environment in many business use cases.

To learn more about  remote desktop, refer

brainly.com/question/4455143

#SPJ4

3 0
2 years ago
What privacy risks do new technologies present,<br> and how do we decide if they're worth it?
vredina [299]

Answer:

Los riesgos de las nuevas tecnologías se multiplican a medida que nos hacemos dependientes de ellas. También lo hacen a medida que sustituyen a otras formas de contacto social más cercanas

Los riesgos de las nuevas tecnologías son grandes desconocidos. El mal uso de las redes sociales y de Internet en los ordenadores y en el teléfono móvil, entre otros factores, supone un peligro real para todos los estratos de población, pero en especial para los más jóvenes. Pensemos, ¿realmente somos conscientes de los riesgos que suponen las nuevas tecnologías? ¿Sabemos cómo utilizarlas para no ponernos en riesgo?

Cabe destacar que las denominadas nuevas tecnologías de la información y de la comunicación (TICs) son un distintivo de la época actual y se han convertido en herramientas esenciales en las diferentes áreas de la vida. Esto es, para el área académica, laboral, social, de ocio…

En la mayoría de los ámbitos están presentes las TICS, pues incluyen las diferentes herramientas con las que nos manejamos hoy en día: servicios de contacto electrónico (e-mails, servicios de mensajería instantánea, chats), los teléfonos móviles, tablets y ordenadores, las plataformas online de difusión de contenidos, las redes sociales, entre otros..

Explanation:

6 0
3 years ago
A _______ attack uses software to try thousands of common words sequentially in an attempt to gain unauthorized access to a user
sergeinik [125]
<h2>A <u>Rogue attack</u> utilizes software just to attempt hundreds of frequent phrases in a row.</h2>

  • Rogue access equipment would be any WLAN radio channel that isn't even authorized to communicate or join the corporate connection.
  • Whenever they have been misconfigured as well as set up without authentication, it creates a new security vulnerability potentially gaining simple access to a private network.

Thus the response above is correct.

Learn more about software attacks here:

brainly.com/question/25407509

7 0
3 years ago
Read 2 more answers
What is contained in the Open Files section of Shared Folders? ​
amm1812

Answer:

The contents of shared folders might include both programs and data files. Common files may be stored and accessed using shared application folders, which simplify administration and offer a single area for users to store and access common data. If all data files are consolidated in a single shared folder, users will have an easier time finding them.

Explanation:

Hope it helps:)

8 0
3 years ago
Many of today’s digital devices operate on battery power supplied by what kind of ion batteries.
stich3 [128]
"Lithium ion" is used in your cellphone.
6 0
3 years ago
Other questions:
  • Calculate the total number of bits transferred if 200 pages of ASCII data are sent using asynchronous serial data transfer. Assu
    5·1 answer
  • The number of bits used to store color information about each pixel is called ____.
    13·1 answer
  • What is the use of form in HTML​
    12·1 answer
  • Java can be used to create which of the following technologies?This task contains the radio buttons and checkboxes for options.
    5·1 answer
  • Write a program in C/C++ to draw the following points: (0.0,0.0), (20.0,0.0), (20.0,20.0), (0.0,20.0) and (10.0,25.0). For this
    6·1 answer
  • EASY What does the Backspace key do?
    6·1 answer
  • The Self-Quiz gives you an opportunity to self-assess your knowledge of what you have learned so far.
    13·1 answer
  • Tips for staying safe using social media. Using in your own words.
    6·1 answer
  • 3. It is important to make certain that your employees are aware of the work ethic
    13·1 answer
  • Bank Account Postings While reviewing your checking account balance online, you notice that debit card purchases have not posted
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!