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 this tutorial! it's very useful
View Tutorial          By: Miguel at 2011-06-26 21:15:00

2. I do my projest in j2me.so please send me your ide
View Tutorial          By: sivasakthivel.s at 2011-06-22 13:26:54

3. hi!
please tell how i got the java comm api

View Tutorial          By: suresh at 2010-08-22 03:29:06

4. It worked. Thank U!
View Tutorial          By: Abhijit Kurane at 2010-12-27 11:01:48

5. hi please help me . i want the full code to send t
View Tutorial          By: Prashant at 2008-04-16 06:08:23

6. Very informative and simple to understand. Thank y
View Tutorial          By: Rosa Vladivord at 2012-12-23 13:00:52

7. Hi, these are the lines i added after i downloaded
View Tutorial          By: sandeep,p at 2012-11-22 10:17:07

8. very good exmpl and explantion
View Tutorial          By: harshita negi at 2013-10-16 02:19:35

9. sir can this be the role of java in internet if no
View Tutorial          By: shantanu khanduri at 2012-05-28 07:00:11

10. Can you give me an example to create InetAddress f
View Tutorial          By: Vaibhav at 2009-12-15 23:37:49