Loading...
Loading...
A library app sets a book's return reminder for the day after the issue date. Read a date as day, month and year and print the next day's date in the same form.
Months have their usual lengths, and February has 29 days in a leap year (divisible by 4 and not by 100, or divisible by 400). If the date read does not exist, such as 31 4 2024 or 29 2 2023, print Invalid date.
day month year, or Invalid date.Example 1
Input
28 2 2024
Output
29 2 2024
2024 is a leap year, so the next day is 29 February.
Example 2
Input
31 12 2023
Output
1 1 2024
The last day of the year rolls over to a new year.
Example 3
Input
31 4 2024
Output
Invalid date
April has only 30 days.
Try the problem first. Open one hint at a time.
First work out how many days the month has, using a switch on the month. Use 0 days for an invalid month.
The date is invalid if the month is invalid or the day is less than 1 or more than the month's days.
For a valid date: if the day is not the last day of the month, just add 1 to the day. Otherwise move to day 1 of the next month, and from December move to January of the next year.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor