反转字符串

package com.ctgu.test_Arithmetic;

import java.util.Stack;

public class ReverseString {

public static String reverse(String originStr) {
    if(originStr == null || originStr.length() <= 1) 
        return originStr;
    return reverse(originStr.substring(1)) + originStr.charAt(0);
}

public static String reverse2(String originStr) {
    if(originStr == null || originStr.length() <= 1) 
        return originStr;
    StringBuffer sb = new StringBuffer();
    for(int i=originStr.length()-1; i>=0; i--){
        sb.append(originStr.charAt(i));
    }
    return sb.toString();
}

public static void reverse3(String originStr) {
    Stack stack = new Stack();
    for(int i=0; i

}
运行结果:
gfedcba
gfedcba
gfedcba

你可能感兴趣的:(反转字符串)