实现字符串的反转

public class Demo {
    public static void main(String[] args) {
        String str = "ABCDEFG";
        StringBuffer sb = new StringBuffer(str);
        StringBuffer reverse = sb.reverse();
        System.out.println(reverse);
        String reverse2 = reverse(str);
        System.out.println(reverse2);
    }
    public static String reverse(String str) {
        if(str == null || str.length() <= 1)
            return str;
            return reverse(str.substring(1)) + str.charAt(0);
    }
}

猜你喜欢

转载自www.cnblogs.com/miye/p/9003315.html