当前位置: 代码迷 >> Java相关 >> 不知道怎么改啊
  详细解决方案

不知道怎么改啊

热度:78   发布时间:2007-05-16 16:08:40.0
不知道怎么改啊
//实现字符串的逆转
import java.io.*;
import java.util.*;
class WriteBackWard{
public static void main(String[] args){
String s="cat";
System.out.println("enter writebackward ,string"+s);
String writebackward(String s){
if(s.length()==0 ){}
//{do nothing --this is the base case}
else
{
System.out.println("About to write the cast derection of string"+s);
System.out.println(s.substring(s.length()-1,s.length()));
s=s.substring(s.length()-1,s.length());
writebackward(s);
}//end if
}//end function
}//end main
}//the end
----------------解决方案--------------------------------------------------------
如果用你的方式来做就要用for来从字符串最大长度开始倒着向前截

----------------------有简单方式-------------------------------
StringBuffer a = new StringBuffer("abcd1243324ll");
System.out.println(a.reverse().toString());
----------------解决方案--------------------------------------------------------
恩确实简单 不过我的错了吗 我运行的时候 出现错误 给我个解答 感谢了

----------------解决方案--------------------------------------------------------
你的当然错了,没有循环怎么可能拿出每个字符了
----------------解决方案--------------------------------------------------------
  相关解决方案