-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
48 lines (34 loc) · 1.54 KB
/
Copy pathMain.java
File metadata and controls
48 lines (34 loc) · 1.54 KB
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
46
47
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
System.out.println("Фамилия Имя Отчество");
System.out.println("Дата рождения формата ДД-ММ-ГГГГ");
String FIO = console.nextLine();
String bithday = console.nextLine();
String[] FIO_attributes = FIO.split(" ");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
LocalDate date_birthday;
LocalDate current = LocalDate.now();
try{
date_birthday = LocalDate.parse(bithday,formatter);
}catch (DateTimeParseException e){
throw new RuntimeException("Неправильный формат даты");
}
int age = current.getYear() - date_birthday.getYear();
if (current.getDayOfYear() < date_birthday.getDayOfYear()) {age--;}
String gender = "М";
try{
if (FIO_attributes[2].charAt(FIO_attributes[2].length() - 1) == 'а') {
gender = "Ж";
}
}catch (ArrayIndexOutOfBoundsException e){
throw new RuntimeException("Неправильный формат ФИО");
}
System.out.format("%s %c.%c.\n",FIO_attributes[0], FIO_attributes[1].charAt(0), FIO_attributes[2].charAt(0));
System.out.println(gender + ' ' + age);
}
}