Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Tuesday, 16 August 2016

palindrome in JAVA

Java program to find word is palindrome or not if not then make it.





import java.io.*;
public class Palindrome {
public static void main(String []argv) throws IOException
{
    String s2 ="";

     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the word");
StringBuffer b=new StringBuffer(br.readLine());
StringBuffer b1=new StringBuffer(b);
for(int i=b.length()-1;i>=0;i--)
{
   s2=s2+b.charAt(i);
}
if(b.toString().equalsIgnoreCase(s2))
{
    System.out.println("----------string is palindrome--------");
}
else
{
    System.out.println("--------string is not palindrome------");
 String b2=b1.reverse().toString();
 b1=b.append(b2);
 System.out.println("---------After making it palindrome-- \n"+b1);
}
}
}

No comments:

Post a Comment