递归判断是否是回文

//A1.java

public class A1 {

    
public static void main(String[] args) {
        String str 
= "madam";
        System.out.println(exec(str, 
0));
    }

    
public static boolean exec(String str, int i) {
        
if (i >= str.length() / 2) {
            
return true;
        } 
else {
            
return str.charAt(i) == str.charAt(str.length() - 1 - i) && exec(str, i + 1);
        }
    }
}

 

运行结果:

true

posted on 2009-11-21 23:51  我为Java而努力  阅读(195)  评论(0)    收藏  举报

导航