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. thank you for your good tutorial about string func
View Tutorial          By: joy at 2010-08-10 04:06:20

2. Thanks...

Rohit
xpode.com

View Tutorial          By: Rohit at 2012-04-30 04:18:12

3. Your explanation is good but, it will be better i
View Tutorial          By: Jabaraj at 2010-03-22 06:02:33

4. I have a site fully based on php and mysql.The log
View Tutorial          By: titus at 2011-06-14 00:52:30

5. hi all i receive below error can any one help me p
View Tutorial          By: Purushothaman at 2009-04-03 17:38:42

6. how to create inode address using c++
View Tutorial          By: pooja at 2014-06-24 05:50:33

7. Very nice tutorial :)

I have teste

View Tutorial          By: yannoo95170 at 2015-06-18 00:30:26

8. Line 11 says:
cout << "Here's a

View Tutorial          By: Nrom at 2012-06-26 20:16:52

9. I have a mac book dual booting with snow leopard (
View Tutorial          By: david at 2015-06-27 15:33:07

10. Very nice tutorial. Hi Rintu for attachment u can
View Tutorial          By: ras at 2013-03-14 17:19:47