Social Icons

19 July 2012

0 Java program to check the palindrome

Following program checks whether a given string is palindrome or not.The logic of program is, first reverse the input string and then check for equality.

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class CheckPalindrome
  {
    public static void main(String args[]) throws Exception
     {
       InputStreamReader isr=new InputStreamReader(System.in);
       BufferedReader br = new BufferedReader(isr); 
       String str1 = new String();
       str1 =br.readLine();
       str1 = str1.toLowerCase();
       String str2 = new StringBuffer(str1).reverse().toString();
       if(str1.equals(str2))
         System.out.println("Palindrome");

       else
        System.out.println("Not Palindrome");
     }
}

Output:

0 comments:

Post a Comment

Hey this is a test comment

Related Posts Plugin for WordPress, Blogger...