当前位置: 技术问答>java相关
在java里,递归的程序怎么写??麻烦随便写个例子出来。谢谢!
来源: 互联网 发布时间:2015-06-04
本文导语: 如题 | easy! public class test { public static int inc(int c) { c++; System.out.println(c); if (c > 10000) return c; else return inc(c); } public static void main(String[] args) { int count = 0; S...
如题
|
easy!
public class test
{
public static int inc(int c)
{
c++;
System.out.println(c);
if (c > 10000) return c;
else return inc(c);
}
public static void main(String[] args)
{
int count = 0;
System.out.println("final:"+inc(count));
}
}
public class test
{
public static int inc(int c)
{
c++;
System.out.println(c);
if (c > 10000) return c;
else return inc(c);
}
public static void main(String[] args)
{
int count = 0;
System.out.println("final:"+inc(count));
}
}