字符串反转
程序员文章站
2024-03-05 15:31:01
...
描述:字符串反转,即把字符串"abcd"变为"dcba"
public static void main(String[] args) {
String str = "abc";
System.out.println(reverse6(str));
}
public static String reverse6(String str) {
int len = str.length();
if (len <= 1) {
return str;
}
String left = str.substring(0, len / 2);
String right = str.substring(len / 2, len);
return reverse6(right) + reverse6(left);
}
上一篇: spring-mvc整合shiro安全框架(权限拦截)
下一篇: Python基础练习题