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. Just what I needed. Thank you.
View Tutorial          By: Clive Jefferies at 2009-06-01 08:05:15

2. I hope so.:d
View Tutorial          By: khoa at 2008-06-10 04:18:31

3. i am newly in java, i want to learn about this and
View Tutorial          By: gelen at 2010-11-23 02:57:15

4. providing explanation about the topics is very use
View Tutorial          By: vikram naidu at 2010-06-09 23:40:41

5. nice one ...
View Tutorial          By: vamsi at 2011-11-11 06:41:25

6. Thank u very much, your topic is very clear, to th
View Tutorial          By: Ahmed Samir at 2011-05-26 23:35:22

7. i thnk exampleThread example is wrong - like billg
View Tutorial          By: oldman at 2011-09-24 12:32:33

8. Thank you! Solved many headaches :)
View Tutorial          By: Dominik at 2013-07-30 16:51:46

9. thank's
View Tutorial          By: gerald at 2010-08-06 01:21:39

10. voire pluse a des command java
View Tutorial          By: lahcine moubarek at 2009-02-16 01:59:17