I tested this extensively and it's working fine but for some reason its failing the test for short string..
package com.codegym.task.task07.task0712;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Shortest or longest
*/
public class Solution {
public static void main(String[] args) throws Exception {
ArrayList<String> strings = new ArrayList<>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < 10; i++) {
strings.add(reader.readLine());
}
int shortest = strings.get(0).length();
int longest = strings.get(0).length();
int longWord = 0;
int shortWord = 0;
for (String string : strings) {
if (string.length() <= shortest) {
shortest = string.length();
shortWord = strings.indexOf(string);
}
if (string.length() > longest) {
longest = string.length();
longWord = strings.indexOf(string);
}
}
if (longWord < shortWord) {
System.out.println(strings.get(longWord));
}
if (shortWord < longWord) {
System.out.println(strings.get(shortWord));
}
}
}