Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How do I make this Palindrome tester ignore punctuation?

  1. #1
    Banned
    Join Date
    Oct 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How do I make this Palindrome tester ignore punctuation?

    Heres the Palindrome Tester:
    //import cs1.Keyboard;
     
    public class PalindromeTester
    {
       //-----------------------------------------------------------------
       //  Tests strings to see if they are palindromes.
       //-----------------------------------------------------------------
       public static void main (String[] args)
       {
          String str, another = "y";
          int left, right;
     
          while (another.equalsIgnoreCase("y")) // allows y or Y
          {
             System.out.println ("Enter a potential palindrome:");
             str = Keyboard.readString();
     
             left = 0;
             right = str.length() - 1;
     
             while (str.charAt(left) == str.charAt(right) && left < right)
             {
                left++;
                right--;
             }
     
             System.out.println();
     
             if (left < right)
                System.out.println ("That string is NOT a palindrome.");
             else
                System.out.println ("That string IS a palindrome.");
     
             System.out.println();
             System.out.print ("Test another palindrome (y/n)? ");
             another = Keyboard.readString();
          }
       }
    }

    How should I make this ignore punctuation?
    Last edited by helloworld922; October 2nd, 2011 at 10:56 PM.


  2. #2
    Member Staticity's Avatar
    Join Date
    Jul 2011
    Location
    Texas
    Posts
    105
    My Mood
    Inspired
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: How do I make this Palindrome tester ignore punctuation?

    This is a nice reference: String (Java 2 Platform SE 5.0)

    To ignore cases.. There is a method just for that. To remove unwanted characters, you can do that as well Enjoy
    Simplicity calls for Complexity. Think about it.

  3. #3
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: How do I make this Palindrome tester ignore punctuation?

    Hopefully you got the answer.

Similar Threads

  1. For each K, output the smallest palindrome larger than K.
    By alekkk in forum Member Introductions
    Replies: 2
    Last Post: July 23rd, 2011, 02:50 PM
  2. stack Palindrome , java
    By Faha in forum Object Oriented Programming
    Replies: 1
    Last Post: May 3rd, 2011, 04:20 PM
  3. Palindrome
    By mag12203 in forum Algorithms & Recursion
    Replies: 13
    Last Post: December 20th, 2010, 08:28 PM
  4. Palindrome Stacks
    By mgutierrez19 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 7th, 2010, 03:05 AM
  5. Check for palindrome numbers
    By SnooSnoo in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 4th, 2010, 06:11 PM