內容 :
迴文的定義為正向,反向讀到的字串均相同
如:abba , abcba … 等就是迴文
請判斷一個字串是否是一個迴文?
輸入說明 :
一個字串(長度 < 1000)
輸出說明 :
yes or no
import java.util.Scanner;
public class a022 {
public static void main(String[] args) {
Scanner sin = new Scanner(System.in);
while(sin.hasNext()){
String a =sin.next();
boolean c = true;
char ans[] = a.toCharArray();
for(int b=0;b<ans.length/2;b++){
if(ans[b]!=ans[ans.length-(b+1)])
c = false;
}
if(c)
System.out.println(“yes");
else
System.out.println(“no");
}
}
}
發表留言