This is my code and it doesn`t work. public class Solution { private static List<String> strings; public static void main(String[] args) throws Exception { int max = 0; strings = new ArrayList<String>(); BufferedReader z = new BufferedReader(new InputStreamReader(System.in)); for(int i = 0; i < 5; i++){ strings.add(z.readLine()); } for(int i = 0; i < 5; i++){ max = strings.get(0).length(); if(strings.get(i).length() > max)max = strings.get(i).length(); } for(int i = 0; i < 5; i++){ if(max == strings.get(i).length())System.out.println(strings.get(i)); } } }