Hi, I passed the task, but am just wondering if there's a simpler solution. I think I wouldn't been able to finish it without method Reverse part, which I found on stack overflow.
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String fileName = bufferedReader.readLine();
bufferedReader.close();
BufferedReader bufferedReader1 = new BufferedReader(new FileReader(fileName));
ArrayList<String> arrayList = new ArrayList<>();
ArrayList<String> arrayList1 = new ArrayList<>();
while (bufferedReader1.ready()) {
String line = bufferedReader1.readLine();
arrayList.add(line);
}
bufferedReader1.close();
for (String s : arrayList) {
arrayList1.add(Reverse(s));
}
for (String s : arrayList1) {
System.out.println(s);
}
}
private static String Reverse(String str) {
StringBuilder result = new StringBuilder();
StringTokenizer st = new StringTokenizer(str, "");
while (st.hasMoreTokens()) {
StringBuilder thisToken = new StringBuilder(st.nextToken());
result.append(thisToken.reverse()).append(" ");
}
return result.toString();
}
}