Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.time.LocalDate;
- import java.time.format.DateTimeFormatter;
- import java.util.Scanner;
- public class HolidaysBetweenTwoDates {
- public static LocalDate convertStringToDate(String dateString) {
- LocalDate date = null;
- DateTimeFormatter df = DateTimeFormatter.ofPattern("d.M.yyyy");
- try {
- date = LocalDate.parse(dateString, df);
- } catch (Exception ex) {
- System.out.println(ex);
- }
- return date;
- }
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- LocalDate startDate = convertStringToDate(scanner.nextLine());
- LocalDate endDate = convertStringToDate(scanner.nextLine());
- int weekDayCount = 0;
- for (LocalDate date = startDate; date.isBefore(endDate.plusDays(1)); date = date.plusDays(1)) {
- boolean isWeekDay = date.getDayOfWeek().getValue() == 6 || date.getDayOfWeek().getValue() == 7;
- if (isWeekDay) {
- weekDayCount++;
- }
- }
- System.out.println(weekDayCount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement