//AIM: Write a Java Program to test the given string is palindrome or not
import java.io.*;
class pal
{
public static void main(String arg[]) throws IOException
{
int i,j,len;
String s;
DataInputStream in=new DataInputStream(System.in);
System.out.print("Enter a string ?");
s=in.readLine();
len=s.length();
System.out.println("Len="+len);
for(i=0,j=len-1;i<(len/2);i++,j--)
{
if(s.charAt(i)!=s.charAt(j))
break;
}
if(i==(len/2))
System.out.println("Pal string");
else
System.out.println("Not a Pal string");
}
}
No comments:
Post a Comment