Min and max Instant units

Report a typo

You are given a list of Instant units. Find how many seconds have passed starting from the minimum unit to the maximum unit. For this purpose, you must explore the minusSeconds() method of the Instant class.

Sample Input 1:

1991-04-15T17:30:00Z
1995-05-23T17:30:00Z
2011-07-22T17:30:00Z
2022-07-04T18:30:00Z

Sample Output 1:

985222800
Write a program in Java 17
import java.util.*;
import java.time.Instant;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
List<Instant> instantList = createInstantList(scanner);

long result = getMaxMinusMin(instantList);

System.out.println(result);
}

public static List<Instant> createInstantList(Scanner scanner) {
List<Instant> instantList = new ArrayList<>();
instantList.add(Instant.parse(scanner.nextLine()));
instantList.add(Instant.parse(scanner.nextLine()));
instantList.add(Instant.parse(scanner.nextLine()));
instantList.add(Instant.parse(scanner.nextLine()));

return instantList;
}

private static long getMaxMinusMin(List<Instant> instantList) {

}
}
___

Create a free account to access the full topic