Using Recursion : Methods « JSP « Java Tutorial






<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>








23.15.Methods
23.15.1.Creating a Method
23.15.2.Declaring Multiple Methods
23.15.3.Using Recursion
23.15.4.Passing Arrays to Methods
23.15.5.Passing the out Object to a Method
23.15.6.Define function before HTML page
23.15.7.Use page level function