Basically I solved it using the previous task way of solving, but now finding the min value.
The code works so I don't know why it's wrong?
Any help is appreciated!
package com.codegym.task.task07.task0709;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
/*
Expressing ourselves more concisely
*/
public class Solution {
public static void main(String[] args) throws Exception {
Scanner input = new Scanner(System.in);
ArrayList<String> list = new ArrayList<>();
for(int i = 0; i<5; i++){
String s = input.next();
list.add(s);
}
//find and replace
String min = list.get(0);
for(String s : list){
if(s.length()< min.length()){
min = s;
}
}
//print out shortest string/s
for(String s : list){
if(s.length() == min.length()){
System.out.println(s);
}
}
}
}