While: Finding a Factorial : Statements « JSP « Java






While: Finding a Factorial

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

           
       








Related examples in the same category

1.Using the continue Statement
2.Using the break Statement
3.While statement
4.Using the while Loop
5.For loop: Using Two Loop Indexes
6.Using the if Statement
7.Testing for Multiple Conditions
8.Using the switch Statement
9.Using an if-else Ladder
10.Nested if Statements
11.Using Compound Statements