Hi all,
Can you help to understand why it fails on conditions 3 and 4?
On the test input it produces the correct output.
Input:
grandfather
grandmother
daughter
program
car
Output:
grandfather
grandmother
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<>();;
public static void main(String[] args) throws Exception {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
// List<String> strings= new ArrayList<>();
int max = 0;
for (int i = 0; i< 5; i++){
String s = reader.readLine();
strings.add(s);
if (s.length()> max) max = s.length();
}
for (int i=0; i< strings.size();i++){
if (strings.get(i).length()== max) System.out.println(strings.get(i));
// System.out.println(s.length());
}
}
}