1、在页面中计算并以文本的方式输出100以内的Fibonacci数列:1、1、2、3、5、8、13、21、34、55、89。 要求:不使用数组,定义三个变量a, a1 和a2,再定义一个变量n用来计数。 % int a=1,a1=1
          1、在页面中计算并以文本的方式输出100以内的Fibonacci数列:1、1、2、3、5、8、13、21、34、55、89。
要求:不使用数组,定义三个变量a, a1 和a2,再定义一个变量n用来计数。
    <%
        int a=1,a1=1,a2=1;
        out.println(a);
        while(a2<100){
            out.println(a2);
            a2= a1+a;
            a= a1;
            a1 = a2;    
        }
    %> 
 
2、使用竖向表格的方式,完成数据的输出,输出形式如下
<p>试问菲波那切数列从第几项开始大于100:</p>
<table border=1 >
<tr>
<th>项序号</th>
<th>值</th>
</tr>
<%
        int a=1,a1=1,a2=1,n=1;
        out.println("<tr>"+"<th>"+n+"</th>");
        out.println("<th>"+a+"</th>"+"</tr>");
        while(a2<100){
            n++;
            out.println("<tr>"+"<th>"+n+"</th>");
            out.println("<th>"+a2+"</th>"+"</tr>");
            a2= a1+a;
            a= a1;
            a1 = a2;    
        }
    %>
</table>
<p>菲波那切数列从第<%=n %>项开始大于100</p> 
 
3、将数据以横向表格的方式输出,上面一行为“项序号”,下面一行为“值”。如下图
1、思路一:利用两个字符串
<p>试问菲波那切数列从第几项开始大于100:</p> <table > <%! String str1="<th>项序号</th>",str2="<th>值</th>"; %> <% int a=1,a1=1,a2=1,n=1; str1+="<td>"+n+"</td>"; str2+="<td>"+a+"</td>"; while(a2<100){ n++; str1+="<td>"+n+"</td>"; str2+="<td>"+a2+"</td>"; a2= a1+a; a= a1; a1 = a2; } out.print("<tr>"+str1); out.print("<tr>"+str2); %> </table> <p>菲波那切数列从第<%=n %>项开始大于100</p>
2、思路二:表格嵌套(较为繁琐)
<p>试问菲波那切数列从第几项开始大于100:</p>
<table>
<th>
<table border=1>
    <tr>
    <td>项序号</td>
    </tr>
    <tr>
    <td>值</td>
    </tr>
</table>
</th>
<%
        int a=1,a1=1,a2=1,n=1;
        out.print("<th><table border=1><tr><td>"+n+"</td></tr><tr><td>"+a+"</td></tr></table></th>");
        
        
        while(a2<100){
            n++;
            out.print("<th><table border=1><tr><td>"+n+"</td></tr><tr><td>"+a2+"</td></tr></table></th>");
            a2= a1+a;
            a= a1;
            a1 = a2;    
        }
    %>
</table>
<p>菲波那切数列从第<%=n %>项开始大于100</p> 
        
             