Programming Tutorials

Comment on Tutorial - Recursion in java By aathishankaran



Comment Added by : Soph

Comment Added at : 2013-02-06 06:11:39

Comment on Tutorial : Recursion in java By aathishankaran
Declaring int result within the method will change the value of result each time you run the method, there is an alternative method :

class Factorial {

int fact(int n)
{
if ( n ==1) return 1;
return n* fact (n-1);
}
}

therefore taking the additional variable 'result' was completely unnecessary. Im in the twelfth grade.


View Tutorial