Answer the question
In order to leave comments, you need to log in
How to determine the number of black Fridays (the 13th) in a year?
All shalom dear friends. Could you explain on your fingers the algorithm for finding the number of Fridays the 13th in a certain year and how it would all look in Java.
In Runet, oddly enough, I did not find any information available for beginners on this topic.
I thank for attention
I supplement a question:
Seen enough of all methods and classes connected with time and date and slightly ohrenel from their abundance. What specific methods need to be used in order to be able to accomplish the plan?
ps sorry for the lack of independence))
Answer the question
In order to leave comments, you need to log in
LocalDate dateInit = LocalDate.of(2018, 1, 1);
while (dateInit.getYear() != 2030) {
if (dateInit.getDayOfWeek() == DayOfWeek.FRIDAY && dateInit.getDayOfMonth() == 13) {
System.out.println(dateInit.toString());
}
dateInit = dateInit.plusDays(1);
}
Loop through the 13th of the year, and if it's Friday, put it in the results array.
Standard functions for working with date / time: give the date as an input (on a cycle, iterate over the 13th day of each month in the desired year), at the output - get the day of the week.
If Friday: +1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question