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



Ask a Question

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. Hi Rajita, in accordance to our 'Privacy Policy' w
View Tutorial          By: webmaster at 2008-03-25 18:49:39

2. ok this is gud example to build an abstract class.
View Tutorial          By: ashish at 2011-12-01 06:22:32

3. It is very Important Site
View Tutorial          By: Shridhar Koli at 2011-12-29 11:43:29

4. Hi,
Pls help me.I need a full java code wit

View Tutorial          By: karan at 2009-11-26 11:29:56

5. Hi, still having problem with 'Permission denied'.
View Tutorial          By: Dorjoo at 2012-05-18 19:00:22

6. @Harshita you cannot test the SMS and call feature
View Tutorial          By: Anonymous at 2013-03-28 01:32:47

7. This is very good article.
View Tutorial          By: Vipin Joshi at 2008-03-27 13:53:26

8. thanx allot its a very good sample , but im trying
View Tutorial          By: Waleed Qaffaf at 2011-06-09 09:37:15

9. Hi,
I am getting this exception..My modem i

View Tutorial          By: puneet at 2010-04-22 10:22:18

10. Good
View Tutorial          By: sandesh at 2009-10-01 01:15:29