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. Sir,
i am implementing the above code in w

View Tutorial          By: Rahul Singh at 2009-09-01 04:23:25

2. hey plz tell me... can the sequenceinputstream be
View Tutorial          By: gaurav at 2010-08-18 17:21:58

3. Hi,

Can anyone suggest a GSM Modem

View Tutorial          By: Archna at 2009-11-06 03:23:14

4. when i use this, the textarea automatically create
View Tutorial          By: gary at 2011-06-08 07:14:09

5. Hi,
Very Nice explanation ,I tried both mem

View Tutorial          By: Harsh Verma at 2013-01-30 13:43:05

6. /* File name : Employee.java */
public abst

View Tutorial          By: Anonymous at 2012-11-16 12:23:17

7. meow is simple and awesome
View Tutorial          By: vishnu prasanth at 2013-01-10 10:00:35

8. good.....not bad. .show me more programs.
View Tutorial          By: saranya at 2011-12-07 08:49:39

9. Would be great if you also showed how to manipulat
View Tutorial          By: Sparx at 2010-01-05 13:51:56

10. Hi people,
for those getting the Time out

View Tutorial          By: Ramlak at 2008-05-08 08:28:29