方法一:JSP脚本片段 <%..%>方式
<table>
<%
for (int x = 1; x < 10; x++) {
%>
<tr>
<%
for (int y = 1; y <= x; y++) {
out.print("<td>"+y + "x" + x + "=" + (x * y) + "\t"+"</td>");
}
%>
</tr>
<%
}
%>
</table>
方法二:JSP声明 <%! ...%>
<table>
<%!
String Multiple(){
int x=1,y=1,z=0;
String s="";
for( x=1; x<10; x++){
s+="<tr>";
for( y=1; y<=x; y++){
s+="<td>"+y+"x"+x+"="+(x*y)+" "+"</td>";
}
for(z=y;z<10;z++){
s+="<td></td>";
}
s+="</tr>";
}
return s;
}
%>
<%=Multiple()%>
</table>
打印样式:
<style>
table{
border: mediumpurple 1px solid;
margin: auto;
}
table tr:nth-child(odd){//奇数
background: lightblue;
}
table tr:nth-child(even){//偶数
background: lightskyblue;
}
tr,td{
border: 1px solid black ;
}
</style>
运行效果: