这段代码能实现递归吗?

shenpower 2006-09-13 11:27:58
程序实现的是:将12345用递归法反向输出.(用JAVA)


public class TURN
{
public static void main(string arg[])
{
String s="12345";
void show()
{
int n=0;
String s1=s.Substring(s.Substring(s.length())+s.Substring(s.length()-1));
n++
if(n>4)
break;
System.out.print(s1);
else
void show();
}
...全文
152 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
日总是我哥 2006-09-13
  • 打赏
  • 举报
回复
沙发,接分.
dashi 2006-09-13
  • 打赏
  • 举报
回复
沙发,接分.
lip009 2006-09-13
  • 打赏
  • 举报
回复
哇哈哈
dreamover 2006-09-13
  • 打赏
  • 举报
回复
to lip009(深蓝忧郁) ( ) 信誉:100 Blog

郁闷,又是你?
dreamover 2006-09-13
  • 打赏
  • 举报
回复
class Test {
public static void main(String[] args) {
String str = "12345";
show(str,str.length());
}
static void show(String str,int idx){
if(idx>0){
System.out.println(str.substring(idx-1,idx));
show(str,idx-1);
}
}
}
lip009 2006-09-13
  • 打赏
  • 举报
回复
public static void main(String[] args) {
System.out.println(re("1234sdf"));
}
public static String re(String str){
String result="";
if(str!=null && str.length()>0){
result = result + str.substring(str.length() - 1, str.length() - 0);
result=result+re(str.substring(0,str.length()-1));
}
return result;
}
tyq0319 2006-09-13
  • 打赏
  • 举报
回复
支持。接分

23,404

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧