My code seems to do the exercise requirements correctly but I'm failing the last two tests. Could anyone help me out with what's wrong? Thank you.
package com.codegym.task.task07.task0708;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Longest string
*/
public class Solution {
private static List<String> strings;
public static void main(String[] args) throws Exception {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
strings = new ArrayList<String>();
ArrayList<String> longestList = new ArrayList<String>();
String longestString = "";
int longestStringLen = 0;
for (int i = 0; i < 5; i++) {
String s = reader.readLine();
strings.add(s);
if (longestStringLen < s.length()) {
longestStringLen = s.length();
longestString = s;
}
if (longestStringLen == s.length()) {
longestList.add(s);
}
}
if (longestList.size() == 0) {
System.out.println(longestString);
} else {
for (int y = 0; y < longestList.size(); y++) {
System.out.println(longestList.get(y));
}
}
}
}