Hi all,
I cannot understand why I cannot pass last requirement. Results seems to be correct. Thanks in advance for any clue!
Best,
Roman
package com.codegym.task.task07.task0708;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.Reader;
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 {
//write your code here
strings = new ArrayList<String>(5);
Reader r = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(r);
for (int i = 0; i < 5; i++)
{
String s = reader.readLine();
strings.add(s);
}
int maxLength = 0;
String longestString = "";
for (String s : strings) {
if (s.length() > maxLength){
maxLength = s.length();
longestString = s;
}
}
for (String d : strings) {
if (d.length() == maxLength){
System.out.println(longestString);
}
}
}
}