這邊簡單使用 JSP 製作一個可以顯示 nxn 乘法表的網頁,由於本站採用的原始碼強調功能擴充「Prism 」不支援 JSP,因此改用 GitHub Gist 展示,僅供參考。
整數變數 int n
,是用來定義 nxn 的,如果輸入 9
就會是 9x9 的乘法表唷!使用 HTML 表格顯示,JSP 方面採用雙迴圈。
▲ 原始碼與執行結果圖。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
nxn 乘法表 | |
By 萌芽系列網站 ‧ Mnya Series Website ‧ Mnya.tw | |
--> | |
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>nxn 乘法表</title> | |
</head> | |
<body> | |
<table border="1"> | |
<% | |
int x,y,n=9; // n 值可修改 | |
for(x=1;x<=n;x++) | |
{ | |
out.print("<tr>"); | |
for(y=1;y<=n;y++) | |
{ | |
out.print("<td>"+x+"x"+y+"="+x*y+"</td>"); | |
} | |
out.print("</tr>"); | |
} | |
%> | |
</table> | |
</body> | |
</html> |
▲ GitHub Gist 展示完整 JSP 原始碼。
贊助廣告 ‧ Sponsor advertisements
留言區 / Comments
萌芽論壇