life is egg
팰린드롬 본문
replaceAll 정규식이용
알파벳만으로 회문문자 판단하기... 정규식이용, 알파벳만 모으자..!
import java.util.*;
class Main {
public static void main(String[] args){
Main T = new Main();
Scanner kb = new Scanner(System.in);
String str = kb.nextLine(); // 띄어쓰기가 있으니까 넥스트라인!쓰자
System.out.print(T.solution(str);
}
public String solution(String s){
String answer = "NO";
//repalceAll은 정규식 표현 가능 ! replace는 불가능
s = s.toUpperCase().replaceAll("[^A-Z]","")
//위 의미는 알파벳이 아니라면 ""해라
String tmp = new StringBuilder(s).reverse().toString();
if(s.equals(tmp)) answer="YES";
retrun answer;
}
}
Comments