class Palindrome
{
public static void main(String args[])
{
String original, reverse=””;
//reading arguments from command-line.
original = args[0];
//returns lenght of the string
int length = original.length();
for ( int i = length – 1 ; i >= 0 ; i– )
reverse = reverse + original.charAt(i);
//checking match between original string and reverse //string
if (original.equals(reverse))
System.out.println(“Entered string is a palindrome.”);
else
System.out.println(“Entered string is not a palindrome.”);
}
}
Compiling and running program:
>javac Palindrome.java
>java Palindrome JAVA
Output :
Entered string is not a palindrome.
Tag

Related Post

Leave a Reply