Can somebody help me to find what is wrong? Im using "max" to find index of longest string, and "count" to check how many times i should display it (if there is more than 1 longest string). It works fine with:
a
aa
aaa
aaaa
aaaa
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 {
strings = new ArrayList<String>();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < 5; i++) {
strings.add(br.readLine());
}
int max = strings.get(0).length();
int count = 0;
for (int i = 0; i < 5; i++) {
if (strings.get(i).length() > max)
max = i;
}
for (int i = 0; i < 5; i++){
if (strings.get(i).length() == strings.get(max).length()) {
count++;
}
}
for (int i = 0; i < count; i++) {
System.out.println(strings.get(max));
}
}
}