Java program checking whether a String is Palindrome or not

//Java program checking whether a String is Palindrome or not

PalindromeStringDemo.java

public class PalindromeStringDemo
{
 public static void main(String[] args)
 {

  //String to check
  String strToTest="malayalam";

  int i;
  int n=strToTest.length();

  String reversedString="";
  for(i=n-1;i>=0;i--)
  reversedString=reversedString + strToTest.charAt(i);

  if(strToTest.equals(reversedString))
  System.out.println(strToTest+ " is a palindrome");
  else
  System.out.println(strToTest+ " is not a palindrome");
 }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s