Помогите!
package com.javarush.task.task07.task0712;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.*;
/*
Самые-самые
*/
public class Solution {
public static void main(String[] args) throws IOException {
//напишите тут ваш код
//создала список строк
ArrayList<String> words = new ArrayList<String>();
//приготовилась к чтению с клавиатуры
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//Считываю с клавиатуры десять слов
for(int i = 0; i < 10; i++){
String str = reader.readLine();
words.add(str);
}
//нахожу самую длинную строку
/*String longestWord = words.get(0);
int longestWordIndex = 0;
for(int i = 0; i < words.size()-1; i++){
String a1 = words.get(i);
String a2 = words.get(i+1);
int b1 = a1.length();
int b2 = a2.length();
if(b1 >= b2){
longestWordIndex = i;
longestWord = words.get(i);
}
}*/
String longestWord = words.get(0);
int longestWordIndex = 0;
for(int i = 1; i < words.size(); i++){
if( words.get(i).length() <= longestWord.length()){
longestWordIndex = i;
longestWord = words.get(i);
}
}
//нахожу самую КОРОТКУЮ строку
String shortestWord = words.get(0);
int shortestWordIndex = 0;
for(int j = 1; j < words.size(); j++){
if( words.get(j).length() <= shortestWord.length()){
shortestWordIndex = j;
shortestWord = words.get(j);
}
}
//Вывод результата
if(shortestWordIndex < longestWordIndex) {
System.out.println(shortestWord);
} else {System.out.println(longestWord);}
//END!!!!!!!!!!!!!!
}
}