-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathBirthday.java
45 lines (35 loc) · 1.19 KB
/
Birthday.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package birthday;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class Birthday {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new FileReader("input.txt"));
String petya = null;
String vasya = null;
while (sc.hasNextLine()){
petya = sc.nextLine();
vasya = sc.nextLine();
}
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yy");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
Date datePetya = null;
Date dateVasya = null;
try{
datePetya = format.parse(petya);
dateVasya = format.parse(vasya);
} catch (ParseException e) {
e.printStackTrace();
}
assert datePetya != null;
assert dateVasya != null;
long difference = dateVasya.getTime() - datePetya.getTime();
int days = (int) (difference / (24 * 60 * 60 * 1000));
FileWriter out = new FileWriter("output.txt");
out.write(String.valueOf(days));
out.close();
}
}