Tuesday, November 3, 2015

Filled Under:

Java program to check whether a string is palindrome or not

Share
import java.io.*;
class Palindrome
{
public static void main(String args[]) throws IOException
{
System.out.println("Enter a string:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringBuffer str1=new StringBuffer(br.readline());
String str2=str1;
StringBuffer str3=new StringBuffer(str1.reverse());
if(str2.equals(str3))
System.out.println("String is palindrome");
else
System.out.println("String is not palindrome");
System.out.println(str1);
}
}

0 comments:

Post a Comment