All test cases should pass. I've noticed sometimes their verification fails if you write the code in a certain format. Not sure what else to say as I'm getting the right answers when running the program no matter what I put in.
package com.codegym.task.task07.task0712;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;/*
Shortest or longest
1. Create a list of strings.
2. Add 10 strings from the keyboard.
3. Find out which string occurs earlier in the list: the shortest or the longest.
If several strings are shortest or longest, then consider the very first such string encountered.
4. Display the string described in Step 3. One string should be displayed.
*/
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
ArrayList<String> list = new ArrayList<>();
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
for(int i = 0; i < 10; i++){
list.add(buff.readLine());
}
int max = 0;
int min = 0;
int shortest = 0;
int longest = 0;
for(int i = 0; i < list.size(); i++){
max = list.get(0).length();
if(list.get(i).length() > max) max = list.get(i).length();
}
for(int i = 0; i< list.size(); i++){
min = list.get(0).length();
if(list.get(i).length() < min) min = list.get(i).length();
}
for(int i = 0; i < list.size(); i++){
if(max == list.get(i).length()) longest = i;
}
for(int i = 0; i < list.size(); i++){
if(min == list.get(i).length()) shortest = i;
}
int top = Math.min(longest,shortest);
String result = list.get(top);
System.out.println(result);
}
}