Java Tutorial/JSP/While — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 08:07, 1 июня 2010
Содержание
Finding a Factorial
<source lang="java">
<HTML>
<HEAD> <TITLE>Finding a Factorial</TITLE> </HEAD> <BODY>
Finding a Factorial
<% int value = 6, factorial = 1, temporaryValue = value; while (temporaryValue > 0) { factorial *= temporaryValue; temporaryValue--; } out.println("The factorial of " + value + " is " + factorial + "."); %> </BODY>
</HTML></source>
Finding Reciprocals
<source lang="java">
<HTML>
<HEAD> <TITLE>Finding Reciprocals</TITLE> </HEAD> <BODY>
Finding Reciprocals
<% double values[] = {4, 3, 2, 1, 0, 1, 2, 3, 4}; int i = 0; while (values[i] != 0){ out.println("The reciprocal = " + 1 / values[i++] + ".
"); } %> </BODY>
</HTML></source>
Using the while Loop
<source lang="java">
<HTML>
<HEAD> <TITLE>Using the while Loop</TITLE> </HEAD> <BODY>
Using the while Loop
<% int value = 5; while (value > 0) { out.println("The value is now " + value-- + ".
"); } %> </BODY>
</HTML></source>