Professional Documents
Culture Documents
Algorithm
Algorithm
1. Start.
2. Accept the date in the format
DD.MM.YYYY from the user.
3. Initialize variables `n` and `K` to zero.
4. Initialize arrays `b` with month numbers
and `c` with corresponding days in each
month.
5. Count the number of dots ('.') in the input
string to determine if it's a valid format.
6. If `K` is zero, print "invalid input" and
exit.
7. Tokenize the input string using '.' as the
delimiter.
8. Parse the tokens into integers for day,
month, and year and store them in variables
`day`, `month`, and `year`.
9. If the year is divisible by 4, update the
days in February to 29.
10. Check if the month is between 1 and 12
(inclusive).
11. If the day is within the valid range for
the given month, calculate the total number
of days passed in the year.
a. Iterate from month 1 to `month - 1`
(exclusive) and accumulate the days of
each month into `n`.
b. Add `day` to `n`.
12. Print the total number of days, i.e., "The
total day = [n]."
13. If any input is out of range, print "wrong
input." 14. End.
Listings:
Variable listing:
Method Listing:
Method prototype purpose
name
accept() void accept() accept and
calculate all
data
main(String void create an
args[]) main(String instance and
args[]) callcreate an
instance and
call accept
Class listing:
Class name purpose
Days The main purpose of this
program is to calculate the
total number of dates
according to the given data