Hi! :) Any ideas whats wrong with this? :) I have no clue at this point.
The "If several strings are the shortest, then you need to display each of them on a new line." While running it works just fine as required.
package com.codegym.task.task07.task0709;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Expressing ourselves more concisely
*/
public class Solution {
//initial value for loop to override in the first iteration
private static int shortestString = Integer.MAX_VALUE;
public static void main(String[] args) throws Exception {
ArrayList<String> strings = new ArrayList<>();
addDataToArray(strings, 5);
findTheShortestStringInArray(strings);
shortestStringDisplayer(shortestString, strings);
}
private static void shortestStringDisplayer(int shortestStringSize, ArrayList<String> strings) {
for (int i = 0; i < strings.size(); i++) {
if (strings.get(i).length() == shortestStringSize) {
System.out.println(strings.get(i));
}
}
}
private static void findTheShortestStringInArray(List<String> strings) {
for (int i = 0; i < strings.size(); i++) {
String s = strings.get(i);
int stringsAreaListLength = s.length();
if (stringsAreaListLength < shortestString) {
shortestString = stringsAreaListLength;
}
}
}
private static void addDataToArray(List<String> strings, int numberOfInputs) throws IOException {
for (int i = 0; i < numberOfInputs; i++) {
strings.add(userKeyInput());
}
}
private static String userKeyInput() throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
return reader.readLine();
}
}