For some reason the for loop wont stop once the if condition is fulfilled. How do i resolve this?
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 {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> strings = new ArrayList<String>();
for(int i=0; i<10; i++){
strings.add(br.readLine());
}
int longest = 0;
for(String string : strings){
if(string.length() >= longest){
longest=string.length();
}
int shortest = Integer.MAX_VALUE;
for(String string2 : strings){
if(string.length() <= shortest){
shortest=string2.length();
}
}
for(int i = 0; i<strings.size(); i++){
if(strings.get(i).length()==shortest || strings.get(i).length()==longest){
System.out.println(strings.get(i));
break;
}
}
}
}}