Nie mam pojęcia czemu nie przechodzi mi ostatnie wymaganie, testuje kod i wydaje mi się że zwraca poprawne wartości.
Ale może ktoś zauważy błąd który popełniłam
package pl.codegym.task.task07.task0712;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
/*
Najkrótszy czy najdłuższy
*/
public class Solution {
public static void main(String[] args) throws Exception {
//tutaj wpisz swój kod
ArrayList<String> list = new ArrayList<>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for(int i = 0; i < 10; i++){
list.add(reader.readLine());
}
ArrayList<String> listCopy = new ArrayList<>(list);
listCopy.sort(Comparator.comparingInt(String::length));
int indexShortest = list.indexOf(listCopy.get(0));
int indexLongest = list.indexOf(listCopy.get(listCopy.size() - 1));
if (indexShortest < indexLongest){
System.out.println(list.get(indexShortest));
} else {
System.out.println(list.get(indexLongest));
}
}
}