Hello everyone,
somehow i can't get this done right, although all the test i"ve done are good. Also when the smallest element is the last one. Where is the mistake?
Thanks in advance
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 {
public static void main(String[] args) throws Exception {
//write your code here
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> list = new ArrayList<String>();
int x =0;
for (int i = 0; i < 5 ; i++) {
list.add(buffer.readLine());
}
for (int i = 1; i < list.size(); i++) {
if (list.get(i).length() < list.get(i - 1).length())
x = list.get(i).length();
else if (list.get(i).length() == list.get(i - 1).length()){
x = list.get(i).length();
}
else if (list.get(i).length() > list.get(i - 1).length())
x = list.get(i - 1).length();
}
for (int a = 0; a < list.size() ; a++) {
if (list.get(a).length() == x){
System.out.println(list.get(a));
}
}
}
}