倒序输出字符串

public static void main(String[] args) {
        String str = "abc";
        getChar(str);
    }
    public static void getChar(String str) {
        if (str.length()==1) {
            System.out.print(str);
        } else {
            String temp = str.substring(str.length() - 1);
            System.out.print(temp);
            String subStr = str.substring(0, str.length() - 1);
            getChar(subStr);
        }
    }

猜你喜欢

转载自blog.csdn.net/cdw_sunshine/article/details/80991613