My solution is displaying the longest string or strings, but codegym validator is not happy with the third and fourth criteria. Anyone have any suggestions on what I can alter to make it happy?
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;
private static List<String> longest = new ArrayList<>();
public static void main(String[] args) throws Exception {
//write your code here
strings = new ArrayList<String>();
int tempMax = 0;
String maxString = "";
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for(int i = 0; i < 5; i++) {
strings.add(reader.readLine());
}
for(int i = 0; i < strings.size(); i++) {
if(strings.get(i).length() > tempMax) {
if(!longest.isEmpty()) {
longest.clear();
}
maxString = strings.get(i);
tempMax = maxString.length();
}
else if(strings.get(i).length() == strings.get(i -1).length()) {
longest.add(strings.get(i));
longest.add(strings.get(i -1));
}
}
if(longest.isEmpty()) {
System.out.println(maxString);
}
else {
for(String string: longest) {
System.out.println(string);
}
}
}
}