package itheima;
import java.lang.reflect.*;
import java.util.*;
public class apple {
/**
* @param args
*/
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
String str1=s1("helloworld");
System.out.print(str1);
String str2=s2("apple");
}
//通过for循环,对换头尾字符串的元素
public static String s1(String str1)
{
char [] c=str1.toCharArray();
for(int x=0,y=c.length-1;x<y;x++,y--)
{
char temp=c[x];
c[x]=c[y];
c[y]=temp;
}
return new String (c);
}
//将String 转换成StringBuffer,通过StringBuffer里的reverse方法进行翻转
public static String s2(String str2)
{
StringBuffer sb=new StringBuffer(str2);
String c=sb.reverse().toString();
return c;
}
}
|
|