declaration.jsp.
- By Dion Almaer
- June 24, 2001
Enterprise Java
Tag Libraries: JSPs in the Enterprise
by Dion Almaer
Listing 1. declaration.jsp.
<%!
// Method to calculate the fibonacci sequence
public static int calculateFibonacci( int num ) {
if (num <= 0) return 0;
if (num == 1) return 1;
int previous1 = 1, previous2 = 0, fib = 0;
for (int i=2; i <= num; i++) {
// the fib is the answer of the previous two answers
fib = previous1 + previous2;
// reset the previous values
previous2 = previous1;
previous1 = fib;
}
return fib;
}
%>
<html>
<head><title> Fibonnaci via a declaration</title></head>
<body>
<h1>Fibonnaci via a declaration</h1>
<br/>
<% for (int x=0; x < 10; x++) { %>
Fibonacci[<%= x %>] = <%= calculateFibonacci( x ) %><br/>
<% } %>
</body>
</html>
About the Author
Dion Almaer is a senior consultant for CustomWare in Boulder, CO. He can be reached at [email protected].