基本表格;
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
-
- html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-
- <html>
-
- <head>
-
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-
- <title>Hello Worldtitle>
-
- head>
-
- <body>
-
- <table border="1">
-
- <% for(int i=1;i<6;i++){ %>
-
-
- <tr bgcolor="aqua">
- <td>metd>
- <td>metd><td>metd><td>metd>
- tr>
-
-
- <% } %>
-
-
- table>
-
- body>
-
- html>
java的语句括在 <%...%> 之间;使用for循环输出
我说的简单算法是指九九乘法表、杨辉三角之类;
九九乘法表;
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
-
- html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-
- <html>
-
- <head>
-
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-
- <title>Hello Worldtitle>
-
- head>
-
- <body>
-
- <table border="1">
-
-
- <% for(int i=1;i<10;i++){ %>
-
- <tr bgcolor="aqua">
-
- <% for(int j=1;j<=i;j++){ %>
-
- <td> <% out.print(j+"*"+i+"="+i*j+" "); %> td>
-
- <% } %>
-
-
- tr>
- <% } %>
-
-
- table>
-
- body>
-
- html>
二层循环;第一层输出
蛇形矩阵;矩阵的斜线上的数字是连续的;
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
-
- html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-
- <html>
-
- <head>
-
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-
- <title>Hello Worldtitle>
-
- head>
-
- <body>
-
- <table border="1">
-
-
- <%
- int row=0, col=0;
-
- int [][] a = new int[8][8];
- int hang = 2,lie = 2;
- a[0][0] =1;
- for (int i = 0; i < 8; i++) {
- for (int j = 0; j < 8; j++) {
- if (j == 8 - 1 - i) break;//对角线元素置空
- a[i][j+1] =a[i][j]+lie;
- lie=lie+1;
- }
-
- if(i==8-1)break;
- a[i+1][0]=a[i][0]+i+1;
- hang+=1;
- lie=hang;
-
- }
- %>
-
-
-
-
- <% for(int i=0;i<8;i++){ %>
-
-
- <tr bgcolor="aqua">
-
-
- <%
- for(int j=0;j<8;j++)
-
- {
-
- if(a[i][j]==0){}
- else
-
- {
-
- %>
-
- <td> <% out.print(a[i][j]); %> td>
-
-
- <% }
-
- col=col+1;
-
- }
-
- row = row + 1;
-
- col = 0;
-
- %>
-
- tr>
-
- <% } %>
-
-
- table>
-
- body>
-
- html>
先用二维数组给蛇形矩阵赋值;C++的蛇形矩阵赋值一般使用 if...else if....形式,直接搬到java会出错;可能二者的 if...else if.... 写法细节有所不同,没研究过;然后使用二层循环,第一层输出tr,第二层控制输出几个td;