Hi,
I meet all conditions except the last one since I am not sure how to do it. I tried to do something like this after the if - statement but it did not work as I hoped. Therefore I deleted it from the code below. So, still I am stuck with how to meet the last condition.
else if (strings.get(i).length() == longest_String.length()) {
System.out.println(strings.get(i));
System.out.println(longest_String);
}
Thanks.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 reader = new BufferedReader(new InputStreamReader(System.in));
String longest_String = "";
for (int i = 0; i <5 ; i++) {
String s = reader.readLine();
strings.add(s);
}
for (int i = 0; i < strings.size() ; i++) {
strings.get(i);
if (strings.get(i).length() > longest_String.length())
{
longest_String = strings.get(i);
}
}
System.out.println(longest_String);
}
}