Results 1 to 2 of 2
  1. #1
    rameshiit19 is offline Member
    Join Date
    Sep 2010
    Rep Power

    Question Finding out number of Palindromes in a Sentence

    I have tried to do a program to find number of palindromes in a sentence but couldn't complete it since I doesn't know to reverse the string and also to remove special characters. Please help!

    My code:

    import java.lang.*;
    class palindrome1
    public static void main(String args[])

    public static void getsentence()
    String sent=" ";
    String s1=" ";
    String[] punct={".",",","?","!"};
    String input=" ";
    String[] temp;
    String[] temp1={ } ;
    String[] revstrng;
    int i=0;
    String delimiter=" ";
    int len=0;

    System.out.println("Enter the Sentence to find Palindrome Count:");

    BufferedReader in=new BufferedReader(new InputStreamReader(;
    System.out.println("The entered sentence is:" + s1);

    for(int j=0;i<temp.length;i++)


    System.out.println("Number of Palindromes in Sentence:" + i);

    catch(Exception e)



  2. #2
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Destiny Islands
    Rep Power


    A reverse method works pretty simply:
    1) Start with the function declaration--it should accept a single String as a parameter.
    2) Begin with an empty String.
    3) Loop through your string (letter for letter), then add each letter to the empty String in reverse order. (That is, if you're looping forward, add each letter to the end of the empty String.)
    4) Return the new string.

    To check if something is not a letter or number, you can use Character.isLetterOrDigit as well as the other functions in that class to broaden your search (i.e. check for unicode, !@#$%^&*()?"', and so on).

    PS: This method will interest you.
    PPS: When comparing strings, use .equals() or .compareTo() as == compares the refences. That is, two separate String objects will never equate using == even if they contain the same characters.
    Last edited by Zack; 09-13-2010 at 03:47 AM.

Similar Threads

  1. Finding a word in a sentence?
    By blackrabbit in forum New To Java
    Replies: 6
    Last Post: 07-22-2010, 11:07 PM
  2. Finding nth prime number
    By dextr in forum New To Java
    Replies: 2
    Last Post: 04-12-2010, 11:42 PM
  3. Finding a number in array close to another number
    By SteroidalPsycho in forum New To Java
    Replies: 2
    Last Post: 02-15-2010, 12:37 AM
  4. finding length on a number
    By thekrazykid in forum New To Java
    Replies: 8
    Last Post: 12-12-2008, 08:07 PM
  5. Finding the highest number
    By jigglywiggly in forum New To Java
    Replies: 7
    Last Post: 11-04-2008, 08:14 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