題目:回文的定義:“回文數”就是正讀倒讀都一樣的整數。如奇數個數字:98789,這個數字正讀是98789 倒讀也是98789。偶數個數字3223也是回文數。字母 abcba 也是回文。判斷一個字符串是否是回文字符串。
1 public class Test4 { 2 public static boolean isHuiWen(String text) { 3 int length = text.length(); 4 for (int i = 0; i < length / 2; i++) { 5 if (text.toCharArray()[i] != text.toCharArray()[length - i - 1]) { 6 return false; 7 } 8 } 9 return true; 10 } 11 12 public static void main(String[] args) { 13 14 String text = "abccba"; 15 System.out.println(isHuiWen(text)); 16 } 17 }