倒叙打印:比如abcdefg,打印结果gfedcba
/*倒叙打印:比如abcdefg,打印结果gfedcba*/
@Test
public void recursion(){
System.out.println(recursion("abcd"));
}
/*递归*/
public static String recursion(String s) {
int length = s.length();
if(length <= 1){
return s;
}
String left = s.substring(0, length / 2);
String right = s.substring(length / 2, length);
return recursion(right) + recursion(left);
}
标签:String,递归,recursion,打印,length,gfedcba
From: https://www.cnblogs.com/haveanicedayfh/p/17129861.html