Problem Description
“回文串”是一個正讀和反讀都一樣的字符串昔案,比如“l(fā)evel”或者“noon”等等就是回文串员辩。請寫一個程序判斷讀入的字符串是否是“回文”轧膘。
Input
輸入包含多個測試實例,輸入數(shù)據(jù)的第一行是一個正整數(shù)n,表示測試實例的個數(shù),后面緊跟著是n個字符串攒岛。
Output
如果一個字符串是回文串,則輸出"yes",否則輸出"no".
Sample Input
4 level abcde noon haha
Sample Output
yes no yes no
JAVA CODE
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
for (int i = 0; i < n; i++) {
String string = cin.next();
char[] strs = string.toCharArray();
boolean kk = true;
for (int j = 0; j < strs.length / 2; j++) {
if (strs[j] != strs[strs.length - j - 1]) {
kk = false;
}
}
if (kk) {
System.out.println("yes");
} else {
System.out.println("no");
}
}
cin.close();
}
}```