Hey guys,
I already tried to vary my code, but unfortunately it doesn't get accepted.
The result are always correct in my opinion. The program calculates the length of the longest word(s) and prints out each word with this length in a new line, just as requested. I would be very glad if someone could help me out! Thanks in advance. :)
package de.codegym.task.task07.task0708;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Längste Zeichenkette
*/
public class Solution {
private static ArrayList<String> strings = new ArrayList<String>();
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int maxlaenge = 0;
int currlaenge = 0;
for (int i = 0; i < 5; i++) {
strings.add(br.readLine());
currlaenge = strings.get(i).length();
if (currlaenge > maxlaenge) {
maxlaenge = currlaenge;
}
}
String currword = "";
for (int k = 0; k < 5; k++) {
currword = strings.get(k);
if (currword.length() == maxlaenge) {
System.out.println(currword);
}
}
}
}