작성
·
343
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
안녕하세요^^
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));
}
}