The program does show the smallest input. I'm unsure of where I went wrong in the code. Your help is appreciated.
package com.codegym.task.task07.task0709;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Expressing ourselves more concisely
*/
public class Solution {
//private static List<String> strings;
public static void main(String[] args) throws Exception {
//write your code here
ArrayList<String> strings = new ArrayList<>();
//ArrayList<String> strings = new ArrayList<String>();
//strings = new ArrayList<String>();
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
//Read 5 strings from the keyboard and add them to the list.
for(int i = 1; i <=5; i++){
String text = read.readLine();
strings.add(text);
}
//Using a loop, find the shortest string in the list.
int smallSize = 0;
String smallest = strings.get(0);
for (int a = 0; a < strings.size(); a++) {
if (strings.get(a).length() < smallest.length()) {
smallSize = strings.get(a).length();
smallest = strings.get(a);
}
}
for (int i = 0; i < strings.size(); i++) {
int size = strings.get(i).length();
if (size == smallSize){
smallest = strings.get(i);
System.out.println(smallest);
}
}
}
}