Oto kod
class Test
{
// method to find factorial of given number
static int factorial(int n)
{
if (n == 0)
return 1;
return n*factorial(n-1);
}
// Driver method
public static void main(String[] args)
{
int num = 5;
System.out.println("Factorial of "+ num + " is " + factorial(5));
}
}
W jaki sposób działa metoda factoiral bo daje num 5 sprawdza warunek a nastepnie jest 5 * factorial(5-1) czyli powinno zwrócić dwadzieścia w jaki sposób to się zmniejsza ?