package 乒乒乓乓;
public class 递归逆转字符串 {
//非递归逆转
public static String reverse(String s)
{
StringBuffer sbf=new
StringBuffer();
char[]
c=s.toCharArray();
for(int
i=0;i<c.length/2;i++)
{
char
temp=c[i];
c[i]=c[s.length()-1-i];
c[s.length()-1-i]=temp;
}
for(int
i=0;i<c.length;i++)
{
sbf.append(c[i]+"");
}
return
sbf.toString();
}
public static String inverse(String
a)
{
if(a.length()==1)
{
return
a;
}
String
sub=a.substring(1);
String
ans=inverse(sub);
return ans+=a.charAt(0);
}
public static void main(String[]
args)
{
String a="ddeggggere";
System.out.println(a+"---afer---"+reverse(a));
System.out.println(a+"---afer---"+inverse(a));
System.out.println("1".length());
}
}