Using Recursion : Method « JSP « Java






Using Recursion

<HTML>
  <HEAD>
    <TITLE>Using Recursion</TITLE>
  </HEAD>

  <BODY>
    <H1>Using Recursion</H1>
    <%!
    int factorial(int n)
    {
        if (n == 1) {
            return n;
        }
        else {
            return n * factorial(n - 1);
        }
    }
    %>

    <%
        out.println("The factorial of 6 is " + factorial(6));
    %>
  </BODY>
</HTML>


           
       








Related examples in the same category

1.Define function
2.Passing the out Object to a Method
3.Declaring Multiple Methods
4.Creating a Method
5.Passing Arrays to Methods