according to the requirement, the code print the most longer string or the two longer, but it's doesn't validate the last second requirement. can you tell me why ?
package fr.codegym.task.task07.task0708;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
La chaîne la plus longue
*/
public class Solution {
private static List<String> chaines;
public static void main(String[] args) throws Exception {
//écris ton code ici
chaines=new ArrayList<>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String word="";
for (int i=0;i<5;i++) {
word = reader.readLine();
chaines.add(word);
}
String mot = "a";
String temoin = "";
String grand2 ="";
for (int i = 0;i<chaines.size();i++) {
temoin = chaines.get(i);
if (temoin.length()>mot.length())
mot=temoin;
if (temoin.length()==mot.length())
grand2=temoin;
}
if (grand2.length()==mot.length()) {
System.out.println(grand2);
System.out.println(mot);
}
else
System.out.println(mot);
}
}