Free Academic Seminars And Projects Reports

Full Version: PROGRAM TO CHECK WHETHER THE STRINGS ARE PALINDROME OR NOT
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code:
import java.io.*;
class Dem20
{
  public static void main(String args[])throws IOException
{
  BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
  int i,n=0;
  String s1;
try
  {
  System.out.println("enter the size of array:");

  n=Integer.parseInt(b.readLine());
  String s=new String[n];
  System.out.println("enter the string:");
  for(i=0;i<n;i++)
  {
  s[i]=b.readLine();
  }
  for(i=0;i<n;i++)
  {
  StringBuffer sb=new StringBuffer(s[i]) ;
  s1=new String(sb.reverse());
  if(s[i].equals(s1))
  {
  System.out.println("String is"+s[i]+""+"palindrome");
  }
  else
  {
  System.out.println("String is"+s[i]+""+"not palindrome");
  }
  }

  }
  catch(Exception e)
  {
  System.out.println(e);
  }
  }
}

OUTPUT
E:\3msc\java\meenu>java Dem20
enter the size of array:
3
enter the string:
aba
joby
jiss
String is aba palindrome
String is joby not palindrome
String is jiss snot palindrome