递归算法 is just a function call itself. The concept is simple, but not easy to understand.An example:main()
{
int result = production(10); // the result is (10*9*8*7...)
}int production(int i)
{
if (i == 1)
{
return 1;
}
else
{
return i * production(i - 1);
}
}
{
int result = production(10); // the result is (10*9*8*7...)
}int production(int i)
{
if (i == 1)
{
return 1;
}
else
{
return i * production(i - 1);
}
}
public static int production(int i)
{
if (i == 1)
{
return 1;
}
else
{
return i * production(i - 1);
}
}
public static void main(String[] args)
{
int result = this.production(10); // the result is (10*9*8*7...)
System.out.println(result);
}