输入描述:
输入包括一行字符串,其长度不超过1000。
输出描述:
可能有多组测试数据,对于每组数据,如果是回文字符串则输出"Yes!”,否则输出"No!"。
输入例子:
hellolleh
helloworld
输出例子:
Yes!
No!
JAVA实现代码:
(一)
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while(in.hasNext()){
String str = in.nextLine();
boolean isPal = true;
for(int i = 0, j = str.length()-1; i < j; i++, j--){
if(str.charAt(i) != str.charAt(j)){
System.out.println("No!");
isPal = false;
break;
}
}
if(isPal){
System.out.println("Yes!");
}
}
}
}
(二)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = null;
while((str = br.readLine()) != null){
int left = 0;
int right = str.length() - 1;
while(left < right){
if(str.charAt(left) != str.charAt(right)){
System.out.println("No!");
break;
}
left++;
right--;
if (left >= right) {
System.out.println("Yes!");
break;
}
}
}
}
}
(三)
import java.util.*;
public class Main{
public static boolean isPalindrome(String str){
String temp = "";
for (int i = 0; i < str.length(); i++){
temp += str.charAt(str.length() - i - 1);
}
return temp.equals(str);
}
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
while (scan.hasNextLine()){
String str = scan.nextLine();
if (isPalindrome(str)) System.out.println("Yes!");
else System.out.println("No!");
}
}
}