I don't know what's wrong.
package com.codegym.task.task22.task2207;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.io.*;
/*
Inverted words
*/
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));
FileReader fileReader = new FileReader(reader.readLine());
BufferedReader bufferedReader = new BufferedReader(fileReader);
String string;
String[] strings;
ArrayList<String> stringArrayList = new ArrayList<>();
while((string = bufferedReader.readLine()) != null)
{
strings = string.split("\\s");
for(String s : strings)
{
stringArrayList.addAll(Arrays.asList(strings));
}
}
fileReader.close();
bufferedReader.close();
for(int i = 0; i < stringArrayList.size(); i++)
{
for(int j = i+1; j < stringArrayList.size(); j++)
{
String first = stringArrayList.get(i);
String second = stringArrayList.get(j);
StringBuilder stringBuilder = new StringBuilder(second);
if(first.equals(stringBuilder.reverse()))
{
Pair pair = new Pair();
pair.first = first;
pair.second = second;
result.add(pair);
}
}
}
reader.close();
for(Pair p: result)
{
System.out.println(p);
}
}
public static class Pair {
String first;
String second;
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;
}
}
}