Program to check if entered string is Palindrome in Java

 public static boolean checkForPalindrome(String reverseString) {
StringBuffer reversedString = new StringBuffer();
char[] reverseArray = reverseString.toCharArray();
for(int i = reverseArray.length-1; i>=0; i--) {
reversedString.append(reverseArray[i]);
}

if(reverseString.equals(reversedString.toString())) {
return true;
} else {
return false;
}
}

public static void main(String[] args) {
boolean reversedString = checkForPalindrome("MADAM");
if(reversedString) {
System.out.println("Entered string is a Palindrome");
} else {
System.out.println("Entered string is not a Palindrome");
}
}

Comments

Popular posts from this blog

Android - Using KeyStore to encrypt and decrypt the data

Stack and Queue

Java Reflection API