-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathExercise.java
More file actions
29 lines (23 loc) · 1.02 KB
/
Exercise.java
File metadata and controls
29 lines (23 loc) · 1.02 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
import java.time.LocalDateTime;
import java.util.Scanner;
public class Exercise {
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
System.out.print("Gib bitte ein Datum ein (dd.mm.yyyy): ");
String input = sc.next();
int day = Integer.valueOf(input.substring(0, 2));
int month = Integer.valueOf(input.substring(3, 5));
int year = Integer.valueOf(input.substring(6, 10));
LocalDateTime inputDate = LocalDateTime.of(year, month, day, 0, 0, 0);
int dayOfInputDate = inputDate.getDayOfYear();
LocalDateTime christmasDate = LocalDateTime.of(year, 12, 24, 0, 0, 0);
int dayOfChristmasDate = christmasDate.getDayOfYear();
System.out.println("Wochentag: " + inputDate.getDayOfWeek());
if (dayOfInputDate > dayOfChristmasDate) {
System.out.println("Tage bis Weihnachten: " + (dayOfInputDate - dayOfChristmasDate));
} else {
System.out.println("Tage bis Weihnachten: " + (dayOfChristmasDate - dayOfInputDate));
}
}
}