[java]代码库
import java.util.Scanner;
import java.lang.String;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String S = input.nextLine();
String S1 = "";
int len = S.length(), i, j;
for(i = 0; i < len; i++)
{
S1 = S.charAt(i) + S1;
}
if(S.equals(S1))
System.out.print("Yes");
else
System.out.print("No");
input.close();
}
}
法2:
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String S = scan.next();
StringBuffer sb = new StringBuffer(S);
//String s1 = sb.reverse().toString();
//System.out.println(s1);
String s = new String(sb.reverse().toString());
if(s.equals(S))
System.out.println("Yes");
else
System.out.println("No");
scan.close();
}
}