palindrome 팰린드롬, 회문
순서를 거꾸로 읽어도 제대로 읽은 것과 같은 단어와 문장.
예) "level", "SOS", "rotator", "nurses run"..
https://www.hackerrank.com/challenges/java-string-reverse/problem?isFullScreen=true
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String A=sc.next();
/* Enter your code here. Print output to STDOUT. */
String tempText = "";
for(int i=A.length(); i>0; i--){
tempText += A.substring(i-1, i);
}
if(A.compareTo(tempText) == 0){
System.out.println("Yes");
}else{
System.out.println("No");
}
}
}
더보기
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward.
Given a string , print Yes if it is a palindrome, print No otherwise.
Constraints
- will consist at most lower case english letters.
Sample Input
madam
Sample Output
Yes
반응형
'HackerRank > JAVA' 카테고리의 다른 글
java String Tokens (0) | 2024.01.17 |
---|---|
Java Anagrams (0) | 2024.01.17 |
Java Substring Comparisons (0) | 2024.01.17 |
Java Substring (0) | 2024.01.16 |
Java Strings Introduction (0) | 2024.01.16 |