The difference between Duration units

Report a typo

Find the Duration units' average and subtract it from the max Duration unit using the minus() method.
Note that you need to implement the getMaxMinusAvg() method to return the result of the subtraction but this doesn't mean that all logic must be there. You can have more methods.

Sample Input 1:

2
3
35
300
300

Sample Output 1:

PT36H40M
Write a program in Java 17
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.*;

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

Duration result = getMaxMinusAvg(durations);

System.out.println(result);
}

public static List<Duration> createDurationList(Scanner scanner) {
List<Duration> list = new ArrayList<>();
list.add(Duration.of(scanner.nextInt(), ChronoUnit.DAYS));
list.add(Duration.of(scanner.nextInt(), ChronoUnit.HOURS));
list.add(Duration.of(scanner.nextInt(), ChronoUnit.MINUTES));
list.add(Duration.of(scanner.nextInt(), ChronoUnit.MINUTES));
list.add(Duration.of(scanner.nextInt(), ChronoUnit.SECONDS));

return list;
}

public static Duration getMaxMinusAvg(List<Duration> durations) {

}
}
___

Create a free account to access the full topic