Hi Everyone,
can anyone help to understand why my code dont pass the test?
Thanks
TooBiee
package com.codegym.task.task07.task0708;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/*
Longest string
*/
public class Solution {
private static List<String> strings;
public static void main(String[] args) throws Exception {
//write your code here
strings = new ArrayList<String>();
Scanner s = new Scanner(new InputStreamReader(System.in));
for(int i = 0; i < 5; i++) {
strings.add(s.nextLine());
}
int max = strings.get(0).length();
ArrayList<String> l = new ArrayList<String>();
l.add(strings.get(0));
for(int i = 0; i < strings.size(); i++) {
if(strings.get(i).length() >= max) {
max = strings.get(i).length();
if(max > l.get(0).length()) {
l.remove(0);
l.add(strings.get(i));
} else if (max == strings.get(i).length() && i != 0) {
l.add(strings.get(i));
}
}
}
for(String str:l) {
System.out.println(str);
}
}
}