the answer is correct but program has not match requirement

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 {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> list = new ArrayList<String>();
for (int i = 0; i < 10; i++) {
String s = reader.readLine();
list.add(s);
}
int longIndex = 0;
int shortIndex = 0;
int firstnumberLength = list.get(0).length();
int secondnumLength = list.get(1).length();
int longest = 0;
int shortest = 0;
if (firstnumberLength > secondnumLength) {
longest = firstnumberLength; //storing longest size niranjit is stored.
// System.out.println(longest);
} else
shortest = secondnumLength; //storing shortest size
for (int j = 0; j < 10; j++) {
if (list.get(j).length() >longest) { //niranjit >=niranjit flase
longest = list.get(j).length(); //niranjit>
longIndex = j;
}
}
for (int k = 0; k < 10; k++) {
if (list.get(k).length() < shortest) {
shortest = list.get(k).length();
shortIndex = k;
}
}
for (int l = 0; l < 10; l++) {
if (longIndex < shortIndex) {
System.out.println("longest:" + list.get(longIndex));
break;
} else if (longIndex > shortIndex) {
System.out.println("shortest:" + list.get(shortIndex));
}
}
}
}