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));
}
}
}
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 {
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));
}
}
}