Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PROGRAM TO CHECK WHETHER THE STRINGS ARE PALINDROME OR NOT
#1

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
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Powered By MyBB, © 2002-2024 iAndrew & Melroy van den Berg.