21.10.04 16:15 작성
·
320
0
package main;
import java.util.Scanner;
public class Main {
public String solution(String str) {
String answer = "YES";
str = str.toUpperCase();
int lt = 0, rt = str.length() - 1;
char[] ch = str.toCharArray();
while (lt < rt) {
char tmp = ch[rt];
ch[rt] = ch[lt];
ch[lt] = tmp;
lt++;
rt--;
}
if (String.valueOf(ch) != str) {
answer = "NO";
}
return answer;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str = scan.next();
Main T = new Main();
System.out.println(T.solution(str));
}
}
답변 2
0
0
2021. 10. 04. 23:29
안녕하세요^^
string 과 문자배열은 문자열 비교가 안됩니다. 아래와 같이 바꿔야 합니다.
import java.util.Scanner;
public class Main {
public String solution(String str) {
String answer = "YES";
str = str.toUpperCase();
int lt = 0, rt = str.length() - 1;
char[] ch = str.toCharArray();
while (lt < rt) {
char tmp = ch[rt];
ch[rt] = ch[lt];
ch[lt] = tmp;
lt++;
rt--;
}
String tmp = new String(ch);
if (!str.equals(tmp)) {
answer = "NO";
}
return answer;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str = scan.next();
Main T = new Main();
System.out.println(T.solution(str));
}
}