Merging date-time instances

Report a typo

Implement a method that takes two instances of LocalDateTime class and merges them into one object by choosing the largest value of each component for the target object. Consider the following components: years, months, days of months, hours, minutes and seconds.

Output the resulting LocalDateTime object.

Sample Input 1:

2018-10-20T22:30
2017-12-30T22:31:45

Sample Output 1:

2018-12-30T22:31:45
Write a program in Java 17
import java.time.LocalDateTime;
import java.util.Scanner;

public class Main {

public static LocalDateTime merge(LocalDateTime dateTime1, LocalDateTime dateTime2) {
// write your code here
}

/* Do not change code below */
public static void main(String[] args) {
final Scanner scanner = new Scanner(System.in);
final LocalDateTime firstDateTime = LocalDateTime.parse(scanner.nextLine());
final LocalDateTime secondDateTime = LocalDateTime.parse(scanner.nextLine());
System.out.println(merge(firstDateTime, secondDateTime));
}
}
___

Create a free account to access the full topic