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



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. please provide Example instanceof With Collection
View Tutorial          By: siddardha at 2010-08-18 00:30:38

2. This example is very good and useful. I request yo
View Tutorial          By: Ambarisha Malladi at 2010-02-10 22:50:38

3. When trying to install Java

i was

View Tutorial          By: Sinmo at 2009-08-30 00:31:33

4. When copying this code into my java IDE, should i
View Tutorial          By: Barabas at 2010-02-11 03:57:09

5. hello,
i have to connect the crystal report

View Tutorial          By: shanmugaraj at 2010-03-03 04:08:30

6. hi,

i'm a jmeter user.in my test i

View Tutorial          By: mahesh at 2015-03-06 16:58:05

7. Good example
View Tutorial          By: Lahiru at 2012-04-09 05:24:21

8. what are benefits of using overriding method?
View Tutorial          By: Ah Socheat at 2013-12-11 04:44:57

9. is there any way to generate report without seagat
View Tutorial          By: Roshni at 2012-10-01 09:32:41

10. Thanks sir i am understand to jdbc but who will ru
View Tutorial          By: Ranjeet singh at 2012-05-04 07:40:29