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 boolean isPalindrome(String s) {
  11.  
  12. for(int i = 0, j = s.length() -1; i < s.length()/2; i++, j--){
  13. String regex = "^[a-zA-Z0-9]+$";
  14.  
  15. while(!Character.toString(s.charAt(i)).matches("[A-Za-z0-9]+") && i < s.length()-1){
  16. i++;
  17. }
  18.  
  19. while(!Character.toString(s.charAt(j)).matches("[A-Za-z0-9]+") && i > 0){
  20. j--;
  21. }
  22.  
  23. if(Character.toLowerCase(s.charAt(i)) != Character.toLowerCase(s.charAt(j)))
  24. return false;
  25. }
  26. return true;
  27.  
  28. }
  29. public static void main (String[] args) throws java.lang.Exception
  30. {
  31. // your code goes here
  32. System.out.println(isPalindrome("A man, a plan, a canal: Panama"));
  33. }
  34. }
Success #stdin #stdout 0.06s 33612KB
stdin
Standard input is empty
stdout
true