fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10.  
  11. static boolean pal(String s){
  12. int i=0,j=s.length()-1;
  13. while(i<j){
  14. if(s.charAt(i)!=s.charAt(j)){
  15. return false;
  16. }
  17. i++;
  18. j--;
  19. }
  20. return true;
  21. }
  22.  
  23. public static void main (String[] args) throws java.lang.Exception
  24. {
  25. // your code goes here
  26. Scanner sc = new Scanner(System.in);
  27. int n = sc.nextInt();
  28. for(int i=0;i<n;i++){
  29. String str = sc.next();
  30. if(pal(str)){
  31. System.out.println(str);
  32. }
  33. }
  34. }
  35. }
Success #stdin #stdout 0.11s 35520KB
stdin
3
abba
radar
malayalam
stdout
abba
radar
malayalam