-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
50 lines (42 loc) · 1.77 KB
/
Copy pathMain.java
File metadata and controls
50 lines (42 loc) · 1.77 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
48
49
50
import java.util.Scanner;
import java.time.LocalDate;
import java.time.format.DateTimeParseException;
import java.time.Period;
public class Main
{
public static char WhatKindOfGender(String patronymic)
{
char endChar = patronymic.charAt(patronymic.length() - 1);
return endChar == 'а' ? 'Ж' : 'М';
}
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.println("Введите Фамилию:");
String surname = s.nextLine();
System.out.println("Введите Имя:");
String name = s.nextLine();
System.out.println("Введите Отчество:");
String patronymic = s.nextLine();
LocalDate birth = null;
while (birth == null)
{
System.out.println("Введите дату рождения (гггг-мм-дд):");
String Birthday = s.nextLine();
try {
birth = LocalDate.parse(Birthday);
} catch (DateTimeParseException e) {
System.out.println("Неверный формат даты. Попробуйте снова.");
}
}
LocalDate currentage = LocalDate.now();
int age = Period.between(birth, currentage).getYears();
String initial1 = Character.toString(name.charAt(0));
String initial2 = Character.toString(patronymic.charAt(0));
char gender = WhatKindOfGender(patronymic);
System.out.println("Фамилия: " + surname);
System.out.println("Инициалы: " + initial1 + "." + initial2 + ".");
System.out.println("Пол: " + (gender == 'М' ? "Мужской" : "Женский"));
System.out.println("Возраст: " + age + " лет");
}
}