I've tried with multiple sets of words and they all worked correctly
package com.codegym.task.task07.task0709;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.List;
/*
Expressing ourselves more concisely
*/
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
Scanner input = new Scanner(System.in);
ArrayList<String> words = new ArrayList<String>();
for (int i = 0; i < 5; i++) {
words.add(input.next());
}
int shortest = 999;
for (String x : words) {
int y = x.length();
if (y < shortest) {
shortest = y;
}
}
for (String x : words) {
if (x.length() == shortest) {
System.out.println(x);
}
}
}
}