Skip to content

Commit e2d612a

Browse files
committed
implement solution
1 parent 0fced0c commit e2d612a

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

Exercise.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
1+
import java.time.LocalDateTime;
2+
import java.util.Scanner;
3+
14
public class Exercise {
25

36
public static void main(String[] args) {
4-
// implement exercise here
7+
@SuppressWarnings("resource")
8+
Scanner sc = new Scanner(System.in);
9+
10+
System.out.print("Gib bitte ein Datum ein (dd.mm.yyyy): ");
11+
String input = sc.next();
12+
13+
int day = Integer.valueOf(input.substring(0, 2));
14+
int month = Integer.valueOf(input.substring(3, 5));
15+
int year = Integer.valueOf(input.substring(6, 10));
16+
17+
LocalDateTime inputDate = LocalDateTime.of(year, month, day, 0, 0, 0);
18+
int dayOfInputDate = inputDate.getDayOfYear();
19+
LocalDateTime christmasDate = LocalDateTime.of(year, 12, 24, 0, 0, 0);
20+
int dayOfChristmasDate = christmasDate.getDayOfYear();
21+
22+
System.out.println("Wochentag: " + inputDate.getDayOfWeek());
23+
if (dayOfInputDate > dayOfChristmasDate) {
24+
System.out.println("Tage bis Weihnachten: " + (dayOfInputDate - dayOfChristmasDate));
25+
} else {
26+
System.out.println("Tage bis Weihnachten: " + (dayOfChristmasDate - dayOfInputDate));
27+
}
528
}
629
}

0 commit comments

Comments
 (0)