Attempted multiple ways and getting the correct output, but the 3 & 4 task requirements show as failures. Attached is one of the working solutions.
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<String>();
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for (int i=0; i<5; i++) {
strings.add(br.readLine());
}
int maxLength = -1;
for (int i=0; i<strings.size(); i++) {
if (strings.get(i).length() > maxLength) {
maxLength = strings.get(i).length();
}
}
for (int i=0; i<strings.size(); i++) {
if (strings.get(i).length() == maxLength) {
System.out.println(strings.get(i));
}
}
}
}