It is necessary to determine whether the string is a palindrome. A palindrome is a string that is written in the same way from left to right and from right to left (including the empty one). When defining " palindrome " strings should be considered only letters and numbers. And spaces, punctuation marks, and also the register of characters should be ignored.
Sample Input: Madam, I'm Adam!
Sample Output: true
You can remove spaces with .replace(" ",""); and how to filter a line from punctuation marks? common code that works on lines without punctuation:
import java.util.Arrays; public class Arr { public Boolean vozvrat(String A){ String B=""; String C=A.replace(" ",""); char[] mass =C.toCharArray(); char[] mass2=new char[mass.length]; for ( int i =mass.length-1; i>= 0;){ for(int j=0;j<mass2.length; j++){ mass2[j]=mass[i]; i--; B+=mass2[j]; } } System.out.println(B); System.out.println(C); return B.equalsIgnoreCase(C); } public static void main(String args[]){ Arr C=new Arr(); System.out.println(C.vozvrat("Madam' I'm Adam")); } }