Results 1 to 3 of 3

Thread: Palindrome

  1. #1
    threlot is offline Member
    Join Date
    Oct 2012
    Rep Power

    Question Palindrome

    How can i fix this problem. When i type for example: "!!radar????" it says that is not a palindrome. Whenever i type different punctuation marks, it says that is not a palindrome.

    The method should ignore spaces and punctuation in the string.

    Java Code:
    import java.util.Scanner;
    public class Palindromes{
        static boolean testPalindrome(String s)
            if(s.length()==0 || s.length()==1)
                return true;
            s=s.toLowerCase().replaceAll(" ", "");
            s = s.replace(".", "");
                return testPalindrome(s.substring(1, s.length()-1));
            return false;
        public static void main(String[] args) 
            Scanner sc = new Scanner(;
            System.out.print("Enter String: ");
            String s = sc.nextLine();
                System.out.println("It's a Palidrome");
                System.out.println("It's not a Palindrome");

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: Palindrome

    Try doing some debugging by printing out the values of the variables as the code executes so you see what the code sees when it executes. The print out will help you understand what the code is doing.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    finest is offline Member
    Join Date
    Nov 2013
    Rep Power

    Default Re: Palindrome

    your program only takes care of spaces and a period characters in the string, include other special characters as well.

Similar Threads

  1. palindrome
    By rochellelising in forum New To Java
    Replies: 1
    Last Post: 08-24-2011, 01:03 PM
  2. Palindrome Recursion
    By jk336699 in forum New To Java
    Replies: 6
    Last Post: 08-24-2011, 06:02 AM
  3. Palindrome
    By leepikamukharji in forum New To Java
    Replies: 2
    Last Post: 04-29-2011, 03:20 PM
  4. Palindrome
    By pinkdreammsss in forum Java Applets
    Replies: 8
    Last Post: 05-04-2010, 03:59 PM
  5. HELP...Palindrome
    By d7o0om in forum New To Java
    Replies: 12
    Last Post: 11-13-2009, 03:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts