If i run my program in IntelliJ, my input and output looks like this:
INPUT: a a as asfd asd OUTPUT: a aThe program reads 5 strings from keyboard, finds the shortest string, displays it, and displays multiples if more than one are the shortest. Yet, none of the conditions pass. The previous task was almost the same, just looking for the maximum number, I'm not sure where I'm going wrong.
package com.codegym.task.task07.task0708;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Longest string
*/
public class Solution {
public static void main(String[] args) throws Exception {
List<String> strings;
strings = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int min = 0;
for (int i = 0; i < 5; i++) {
String s = reader.readLine();
strings.add(s);
}
min = strings.get(0).length();
for(int i = 0; i < strings.size(); i++) {
if (strings.get(i).length() < min)
min = strings.get(i).length();
}
for(int i = 0; i < 5; i++) {
if (min == strings.get(i).length())
System.out.println(strings.get(i));
}
}
}