Tuesday, 10 December 2013

Java - How to check Palindrome

public class palindrome {
public static void main(String[] args) {
String original, reverse="";
        original = "jaj";
        int length = original.length();
        for ( int i = length - 1 ; i >= 0 ; i-- )
           reverse = reverse + original.charAt(i);
        if (original.equals(reverse))
           System.out.println("Palindrome, Original - "+ original+ " Reversed - " + reverse);
        else
          System.out.println("Not a Palindrome, Original - "+ original+ " Reversed - " + reverse);
}

}

No comments:

Post a Comment