Posted by : Unknown domingo, 28 de septiembre de 2014

Friday, September 12th, 2014

Recursion 

By: Eduardo Zavala Ramírez

We did some exercises applying the recursion concept, one of the simplest examples is to calculate the factorial of a number.  
Below, you will find the code lines used in the application.

package calcularFactorial;

public class appFactorial {

    public static void main(String[] args) {
        System.out.println(" El factorial del número ingresado es: "+Factorial(5));

    }
   
    public static long Factorial (int n)
    {
        if(n==1)
        {
            return 1;
        }
        else
        {
            return Factorial(n-1)*n;
        }
    }

}


The activity was a success and it made possible to understand the recursion concept.

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Welcome to My Blog

Popular Post

Blogger templates

Con tecnología de Blogger.

- Copyright © Zavala Zavala - Computing and Problem Solving -Robotic Notes- Powered by Blogger - Designed by Johanes Djogan -