I tested my code and works fine. Any idea what's wrong?
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 = new ArrayList<>();
public static void main(String[] args) throws Exception {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int max = 0;
//add strings to the list,
for (int i = 0; i < 5; i++) {
strings.add(reader.readLine());
}
//find the longest string
for (int i = 0; i < strings.size(); i++) {
if(strings.get(i).length() > max)
max = strings.get(i).length();
}
// if the string's length equals to max, print it.
for (int i = 0; i < strings.size(); i++) {
if(strings.get(i).length() == max)
System.out.println(strings.get(i));
}
}
}