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

Java program to get location meta data from an image

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

Archived Comments

1. This explaination is good to understand the basic
View Tutorial          By: Nisha Thankachan.F at 2013-02-13 05:29:13

2. Error loading SolarisSerial: java.lang.Unsatisfied
View Tutorial          By: koteshwar at 2011-02-05 05:33:19

3. Hi hardik,

RMS sample program is av

View Tutorial          By: Daniel Malcolm at 2008-03-29 19:46:18

4. I'm trying to follow this backward, but I can't fi
View Tutorial          By: DMM at 2014-03-14 21:42:06

5. hi frnds help me please .javamail program not bee
View Tutorial          By: sella at 2011-10-05 18:33:22

6. i get this msg when one of the clients close there
View Tutorial          By: Zero Code at 2009-07-16 14:05:14

7. Hai people plz help it's urgent, i got no errors i
View Tutorial          By: Hopewell at 2011-10-13 22:57:45

8. thanks a lot it was really helpful...........for d
View Tutorial          By: Joshi Rocky at 2010-01-29 14:13:40

9. Very precise and informative tutorial. Appreciated
View Tutorial          By: Rishi Raj at 2011-07-08 12:25:04

10. Can u plz send me woking application (Send sms) J
View Tutorial          By: Ritanshu Goel at 2012-09-22 05:52:49