-
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.
-
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.
-
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
Forum Rules
|
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
|
Bookmarks