import
java.util.Scanner;
class StringEx
{
public static
void main(String args[])
{
Scanner s=new
Scanner(System.in);
String ex=new
String();
Boolean
pal=true;
System.out.println("Enter
a string:");
ex=s.nextLine();
for(int
i=0;i<(ex.length()/2);i++)
if(ex.charAt(i)!=ex.charAt(ex.length()-i-1))
{
pal=false;
break;
}
if(pal==true)
System.out.println("The
string is a palindrome.");
else
System.out.println("The
string is not a palindrome.");
}
}
OUTPUT:
C:\Java\jdk1.7.0\bin>java
StringEx
Enter a string:
malayalam
The string is a
palindrome.
No comments:
Post a Comment