Can't see the reason this fails. Is the checker doing something wrong?
package com.codegym.task.task07.task0712;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
/*
Shortest or longest
*/
public class Solution {
public static void main(String[] args) throws Exception {
ArrayList<String> input = new ArrayList<>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < 10; i++) {
String s = reader.readLine();
input.add(s);
}
reader.close();
ArrayList<Integer> lengths = new ArrayList<>();
for (String s : input) {
lengths.add(s.length());
}
ArrayList<Integer> sorted = new ArrayList<>(lengths);
Collections.sort(sorted);
int min = sorted.get(0);
int max = sorted.get(9);
int first = 0;
int second = 0;
for (int i = 0; i < 10; i++) {
if (lengths.get(i) == min) {
first = i;
break;
}
}
for (int i = 0; i < 10; i++) {
if (lengths.get(i) == max) {
second = i;
break;
}
}
if (first < second) System.out.println(input.get(first));
else System.out.println(input.get(second));
}
}