递归转循环
下面的代码是求花朵儿数的,使用了递归,我想改成循环来做,改怎么写呢?注意:不要用栈和过多的循环public static void main(String[] args) {java 递归 --------------------编程问答-------------------- http://bbs.csdn.net/topics/390632430
foo(7,0,0,0);
}
static void foo(int n, int level, int s, int p)
{
if (level < n)
{
for (int i = (level == 0)? 1:0; i <= 9; i++)
foo(n, level + 1, 10 * s + i, (int) (p + Math.pow(i, n)));
}
else if (p == s)
System.out.println(p);
}
补充:Java , Java SE