DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  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));
    }
    }

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links