Get Adobe Flash player

Saturday, January 14, 2012

String Palindrome or not

import java.io.*;

public class Palindrome {
public static void main(String [] args){
try{
BufferedReader object = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter string");
String s=object.readline();
int i;
int n=s.length();
String str="";
for(i=n-1;i>=0;i--)
str=str+s.charAt(i);
if(str.equals(s))
System.out.println(s+ " is palindrome");
else
System.out.println(s+ " is not a palindrome");
}
catch(Exception e){
System.out.println("Input Error!");
}
}
}


Output:



Enter string abbsd

abbsd is not palindrome



Enter string abcdedcba

abcdedcba is palindrome

0 comments:

Post a Comment