Все выводит как надо но не проходит последнее условие
package com.javarush.task.task22.task2207;
import java.io.*;
import java.util.LinkedList;
import java.util.List;
/*
Обращенные слова
*/
public class Solution {
public static List<Pair> result = new LinkedList<>();
public static void main(String[] args) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
File fis = new File(reader.readLine());
FileInputStream file = new FileInputStream(fis);
byte[] data = new byte[(int) fis.length()];
file.read(data);
String temp = new String(data).replace("\r\n"," ");
String[] buffer = temp.split(" ");
for (int i=0; i<buffer.length; i++){
for (int j = i+1; j<buffer.length;j++){
StringBuilder s2 = new StringBuilder(buffer[j]).reverse();
if (buffer[i].equals(s2.toString())) {
result.add(new Pair(buffer[i],buffer[j]));
//System.out.println(buffer[i] + " " + buffer[j]);
buffer[i]=""+Math.random();
buffer[j]=""+Math.random();
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static class Pair {
String first;
String second;
public Pair() {
}
public Pair(String first, String second) {
this.first = first;
this.second = second;
}
@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 != null ? second :
second == null && first != null ? first :
first.compareTo(second) < 0 ? first + " " + second : second + " " + first;
}
}
}