I Got The Desired Output:
Grandfather
Grandmother
Still Two Condition Are Not Fulfilled.
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 {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String s;
strings = new ArrayList<String>();
//ArrayList<String> list = new ArrayList<String>();
int index = 0;
for(int i=0; i<5; i++){
s = reader.readLine();
strings.add(s);
}
for(int i=0; i<5; i++){
if(strings.get(i).length() >= index){
index = strings.get(i).length();
System.out.println(strings.get(i));
}
}
}
}