6. แยกย่อย

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 6-22  เมท็อดการตรวจสอบพาลินโดรม (แบบเรียกซ้ำ)
  public static boolean isPalindrome(String word) {
    int n = word.length();
    if (n < 2) return true;
    String c1 = word.substring(0, 1);
    String c2 = word.substring(n - 1, n);
    if (!c1.equalsIgnoreCase(c2)) return false;
    return isPalindrome(word.substring(1, n - 1));
  }
©2009 S.Prasitjutrakul