This seems to be the same issue I am having with similar problems. The output appears to meet all the requirements, but the system is telling me the requirements are not met. I don't know what mistake I am making. Please help!
package com.codegym.task.task07.task0712;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Shortest or longest
*/
public class Solution {
public static void main(String[] args) throws Exception {
ArrayList<String> list = new ArrayList<String>();
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
boolean flag = false;
for (int i=0; i<10; i++){
String s = br.readLine();
list.add(s);
}
String shortest = list.get(0);
String longest = list.get(0);
for (int i=0; i<list.size(); i++){
if (shortest.length()>list.get(i).length()){
shortest=list.get(i);
flag = false;
}
if (longest.length()<list.get(i).length()){
longest=list.get(i);
}
if (flag = false)
System.out.println(shortest);
else if (flag = true)
System.out.println(longest);
break;
}//write your code here
}
}