Question:
Given a string, determine if it is a palindrome, considering only alphanumeric characters.
Palindrome
A palindrome is a word, number, phrase, or other sequences of characters which read the same backwards and forwards.
package learningJava;
import java.util.*;
public class regPract {
/* Find the maximum and minimum element in an array
*/
public static boolean checkPalindrome(String str, String rev ) {
if(str.equals(rev)) {
return true;
}
return false;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter String:");
String str = scan.nextLine();
String rev = "";
for(int i = str.length()-1; i >= 0 ; i-- ) {
rev = rev+str.charAt(i);
}
checkPalindrome(str,rev);
boolean isPalindrome = checkPalindrome(str, rev);
if (isPalindrome) {
System.out.println("The string is a palindrome.");
} else {
System.out.println("The string is not a palindrome.");
}
}
}
Comments
Post a Comment