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.
Printable View
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.
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.
//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));
}
}