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. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. isPalindrome("ab");
  13. }
  14.  
  15. public static boolean isPalindrome(String s) {
  16. if(s == null || s.length() <= 1)
  17. return true;
  18. char ch[] = s.toCharArray();
  19.  
  20. for(int i = 0; i < ch.length ;i++){
  21. if((ch[i] <= 'Z' && ch[i] >= 'A') || (ch[i] <= 'z' && ch[i] >= 'a')|| (ch[i] <= '9' && ch[i] >= '0'))
  22. sb.append(ch[i]);
  23. }
  24. System.out.print(sb);
  25. String s1 = sb.reverse().toString();
  26. String s2 = sb.toString();
  27. System.out.print(s1 +" "+s2);
  28. if(s1.equalsIgnoreCase(s2))
  29. return true;
  30.  
  31. return false;
  32. }
  33. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
abba ba