public class Test8
{
public static void main(String[] args)
{
//初始化String类对象str
String str = "abcde";
//调用方法reverse()
System.out.println(reverse(str));
}
private static String reverse(String str)
{
//初始化对象result
String result = "";
//将字符串转变为数组
char[] c = str.toCharArray();
for (int i = c.length-1; i >= 0 ; i--)
{
result += c[i];
}
return result;
}
}
|
|