Comment on Tutorial - Recursion in java By aathishankaran



Comment Added by : Søren

Comment Added at : 2011-09-22 03:13:53

Comment on Tutorial : Recursion in java By aathishankaran
Now what the hell does all this mean???
To better understand how the fact() method works, let’s go through a short example. When you compute the factorial of 3, the first call to fact() will cause a second call to be made with an argument of 2. this invocation will cause fact() to be called a third time with an argument of 2. This call will return 1, which is then be called a third time with an argument of 1. This call will return1, which is then multiplied by 2 (the value of n in the second invocation). This result (which is 2) is then returned to the original invocation of fact() and multiply by 3 ( the original value of n). This yields the answer, 6. You might find it interesting to insert println() statements into fact() which will show at what level each call is and what the intermediate answers are.


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. I want simple programs using BuffuredReader for m
View Tutorial          By: Why ask my name? at 2013-06-01 04:56:00

2. I used two phrases of the security section for the
View Tutorial          By: pabo at 2010-04-05 05:22:24

3. really great, goes more in depth than cplusplus.co
View Tutorial          By: ss80 at 2008-07-02 06:45:47

4. Its working Great.
Here i want to ask one

View Tutorial          By: Manish at 2015-03-18 11:55:20

5. nice...cleared this example....
View Tutorial          By: Waqas Mughal at 2010-03-13 21:21:46

6. the language of your information is easu and more
View Tutorial          By: shivprakashmeena at 2010-08-06 22:18:09

7. I did not understand it. please give one example e
View Tutorial          By: farhaan at 2008-03-20 12:06:11

8. hey plz tell me... can the sequenceinputstream be
View Tutorial          By: gaurav at 2010-08-18 17:21:58

9. Hi, I have the following element:

&

View Tutorial          By: gardek at 2009-09-02 14:40:37

10. Thank you very much. This is the easiest and also
View Tutorial          By: Mehmet Üsküp at 2013-06-17 21:08:08