The code shows the correct answers, still it gives more two wrong requirements!
What is the issue?
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;
public static void main(String[] args) throws Exception {
// Initialize the list of strings
Solution.strings = new ArrayList<String>();
//Read 5 strings from the keyboard and add them to this list.
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for (int i=0; i<5;i++)
{
String s = reader.readLine();
strings.add(s);
}
// Using a loop, find the longest string in the list.
int sizeofElement=0; // to compare with length of each element in the list
String getString = null; // to get the longest string in the list
ArrayList<String> check = new ArrayList<String>(); // to add more than one string that qualify
for(int j=0; j<strings.size();j++){
if (strings.get(j).length()>=sizeofElement){
sizeofElement = strings.get(j).length();
getString = strings.get(j);
check.add(getString);
}
}
//Using a loop to print the check list
for ( int i = 0 ; i<check.size();i++){
System.out.println( check.get(i));
}
}
}