2
I would like to understand, because I can’t see mentally how it occurs in the excerpt: Return fat ː factorial.factoring(fat-1);, the issue of recursion, in what concerns the calls of the method itself factoring in relation to multiplication with fat.
public class FatorialRecursiva
{
public static void main(String[] args)
{
FatorialRecursiva fatorial = new FatorialRecursiva();
double dado = 5.0;
dado = fatorial.fatorar(dado);
System.out.print(dado);
}
public double fatorar(double fat)
{
if (fat < 2)
{
return 1;
}else
{
return fat * fatorar(fat-1);
}
}
}
He creates another instance to solve the "subproblema", which you see creates another, and so it goes .... The definition of recursion is not necessarily, "a method calling itself"
– mau humor
these instances make no sense... recursiveness will happen, but in an unsanctioned way..
– Daniel Omine
Daniel Omine, as I said in another report, had not realized that he had instantiated the class both in the main method and in the factoring, corrected and I hope that now is correct.
– Bruno Silva
@Brunosilva If you want to better understand how the step-by-step execution of a function/method works
recursivo
here an example: http://answall.com/questions/111520/d%C3%Bavida-com-recursividade *Obs - Great care should be taken with recursive functions/methods, as they can be entered into infinite loop easily!– Igor Mello