Saturday, 1 September 2012

String Palindrome java program


Output
Himanshu is not a palindrome.
Source code
StringPalindrome.java

package com.swain.cell;

public class StringPalindrome {
       public static void main(String args[])
          {
             String original="Himanshu";
             String rev="";
                      
             int length = original.length();
        
             for ( int i = length - 1 ; i >= 0 ; i-- )
                rev = rev + original.charAt(i);
        
             if (original.equals(rev))
                System.out.println(original+" is a palindrome.");
             else
                System.out.println(original+" is not a palindrome.");
        
          }
}


No comments:

Post a Comment