You are hereArray / Recursive function in JSP

Recursive function in JSP


This snippet demonstrates how to constructs a function and how to implement factorial function in recursive mode.


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


           
       



Syndicate

Syndicate content

Navigation

AdSense