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. Thanks for good atricle. But this code will always
View Tutorial          By: Binod Suman at 2009-05-28 09:40:48

2. Good and optimum introduction to J2ME application
View Tutorial          By: sabextcc10@gmail.com at 2013-01-14 10:37:57

3. hello sir , i just implement your code and modify
View Tutorial          By: tushar at 2012-01-31 05:21:37

4. What if I wanted POST instead of GET?
View Tutorial          By: Otto at 2011-06-12 15:38:50

5. u can try this out it will satisify u:)
imp

View Tutorial          By: vallabh at 2014-10-04 17:44:18

6. Excellent
View Tutorial          By: Jaleel at 2009-10-16 23:22:52

7. hi i unable to retrive am getting below excepti
View Tutorial          By: vignesh at 2015-03-25 17:14:58

8. I used HyperTerminal directly to check whether mod
View Tutorial          By: Pugal at 2009-10-15 03:38:08

9. how come its able to copy from copyFrom to CopyTo.
View Tutorial          By: sameera at 2015-09-12 13:56:29

10. help me pls example ng c++ program code using do
View Tutorial          By: diana bernardo at 2010-10-15 23:34:19