Finding a Factorial : While « JSP « Java Tutorial






<HTML>
  <HEAD>
    <TITLE>Finding a Factorial</TITLE>
  </HEAD>

  <BODY>
    <H1>Finding a Factorial</H1>
    <%
        int value = 6, factorial = 1, temporaryValue = value;

        while (temporaryValue > 0) {
            factorial *= temporaryValue;
            temporaryValue--;
        }

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








23.9.While
23.9.1.Using the while Loop
23.9.2.Finding a Factorial
23.9.3.Finding Reciprocals