//Written by Tanya Khovanova and Sergei Bernstein import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * PalindromeFinder takes lines of text on standard input and prints * each line which is a strict palindrome to standard output. * A string is a strict palindrome if its reverse is equal to itself. */ public class PalindromeFinder { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader( new InputStreamReader(System.in)); for(String dictWord = reader.readLine(); dictWord != null; dictWord = reader.readLine()) { if (isPalindrome(dictWord)) System.out.println(dictWord); } } public static boolean isPalindrome(String word) { StringBuffer bufferOfWord = new StringBuffer(word); String wordBackwards = (bufferOfWord.reverse()).toString(); return (word.equals(wordBackwards)); } }