17 - 判断回文
Time Limit: 1000 Memory Limit: 65535
Submit: 648 Solved: 385
Description
编码实现:输入一个字符串,判断该字符串是否是回文(回文是指将该字符串含有的字符逆序排列后得到的字符串和原字符串相同的字符串)如果是回文,则输出“Yes”;否则输出“No”。
Input
判定是否是回文的字符串
Output
“Yes”或者“No”
Sample Input
TooooT
Sample Output
Yes
import java.util.Scanner;
public class Main{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String str = in.next();
StringBuffer sb = new StringBuffer(str);
sb.reverse();// 将Str中的字符串倒置
int count = 0;
for(int i = 0; i < str.length(); i++)
{
if (str.charAt(i) == sb.charAt(i))
{
count++;
}
}
if(count == str.length())
{
System.out.print("Yes");
}
else
System.out.print("No");
}
}