Creating Program to test for a Palindrome


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Creating Program to test for a Palindrome

Hybrid View

  1. #1
    T. Best-Tunis Guest

    Creating Program to test for a Palindrome


    I am stuck on creating a program to check if the string inputted is a PALINDROME,
    can anyone suggest any different types of codes that I could try to get this
    programming working.

  2. #2
    Paul Clapham Guest

    Re: Creating Program to test for a Palindrome

    If the length of the string is N, then it has characters at positions 0 to
    N-1, so you have to check that the character at position I is equal to the
    character at position N-1-I for all values of I.

    PC2

    "T. Best-Tunis" <trabird@netzero.net> wrote in message
    news:3ad3b356@news.devx.com...
    >
    > I am stuck on creating a program to check if the string inputted is a

    PALINDROME,
    > can anyone suggest any different types of codes that I could try to get

    this
    > programming working.




  3. #3
    mehrez Guest

    Re: Creating Program to test for a Palindrome


    //Aya baba haw el code elli thibb alih:

    here you find the code that you look for:


    public class CheckForPalindrom
    {

    public CheckForPalindrom()
    {
    }

    static boolean isPalindrom(String stringToCheck)
    {
    boolean palindrom = true;
    if (stringToCheck == null)
    return false;
    else
    {
    int i = 0;
    int j = stringToCheck.length()-1;
    while (i < j && palindrom)
    {
    palindrom = stringToCheck.charAt(i) == stringToCheck.charAt(j);
    i++;
    j--;
    }
    }
    return palindrom;
    }

    public static void main(String[] args)
    {

    //its just for test
    // dont be worry i had tried this class and it work perfectly

    System.out.println(CheckForPalindrom.isPalindrom("hello"));
    System.out.println(CheckForPalindrom.isPalindrom("helleh"));
    System.out.println(CheckForPalindrom.isPalindrom(null));
    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center