что не так?
package com.javarush.task.task22.task2207;
import java.io.*;
import java.util.*;
/*
Обращенные слова
*/
public class Solution {
public static List<Pair> result = new LinkedList<>();
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try(BufferedReader fileRider = new BufferedReader(new InputStreamReader(new FileInputStream(reader.readLine())))) {
StringBuilder text = new StringBuilder();
while(fileRider.ready()) text.append(fileRider.readLine()).append(" ");
String[] words = text.toString().split(" ");
for(int i=0;i<words.length-1;i++) {
for (int k = i + 1; k < words.length; k++) {
if (words[i] == null && i < words.length - 1) {
i++;
} else if (i == words.length - 1){ break;
} else if (words[k] != null) {
if (words[i].equals(new StringBuilder(words[k]).reverse().toString())) {
result.add(new Pair(words[i], words[k]));
words[i] = null;
words[k] = null;
i++;
}
}
}
}
System.out.println(result.toString());
} catch (IOException e) {e.printStackTrace();}
}
public static class Pair {
String first;
String second;
public Pair(String second, String first) {
this.second = second;
this.first = first;
}
public Pair() {
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair pair = (Pair) o;
if (first != null ? !first.equals(pair.first) : pair.first != null) return false;
return second != null ? second.equals(pair.second) : pair.second == null;
}
@Override
public int hashCode() {
int result = first != null ? first.hashCode() : 0;
result = 31 * result + (second != null ? second.hashCode() : 0);
return result;
}
@Override
public String toString() {
return first == null && second == null ? "" :
first == null ? second :
second == null ? first :
first.compareTo(second) < 0 ? first + " " + second : second + " " + first;
}
}
}