Advertisement
marking2112

DaySum

Jul 9th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. import java.time.LocalDate;
  2. import java.time.format.DateTimeFormatter;
  3. import java.util.Date;
  4. import java.util.Scanner;
  5.  
  6. public class P11_Date {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         int n = Integer.parseInt(scanner.nextLine());
  11.  
  12.         String firstDate = scanner.nextLine();
  13.         String secondDate = scanner.nextLine();
  14.  
  15.         DateTimeFormatter format = DateTimeFormatter.ofPattern("dd-MM-yyyy");
  16.  
  17.         int firstCount = 0;
  18.         int secondCount = 0;
  19.         for (int i = 1; i <= n; i++){
  20.  
  21.             if (i % 2 == 0){
  22.                 firstCount ++;
  23.             } else {
  24.                 secondCount ++;
  25.  
  26.             }
  27.         }
  28.         LocalDate first = LocalDate.parse(firstDate, format).plusDays(firstCount);
  29.         LocalDate second = LocalDate.parse(secondDate, format).plusDays(secondCount);
  30.  
  31.         int firstDays = first.getDayOfMonth();
  32.         int secondDays = second.getDayOfMonth();
  33.  
  34.         System.out.println(firstDays + secondDays);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement