<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<br>Html打印杨辉三角形
<script type="text/javascript">
{
var n=20;
var a = new Array(n);
var i,j;
for (i = 1; i <= n; i++)
{
a[i] = new Array(n);
for(j=1;j<=i;j++)
{
if(j==1)
a[i][j]= 1;
else
a[i][j]=a[i-1][j]+a[i-1][j-1];
document.write(a[i][j]+" ")
}
document.write("</br>")
}
}
</script>
<br>
<br>Jsp打印杨慧三角形
<%!
int n=20;
int[][] a = new int [n][n];
int i,j;
%>
<%
for(i=0;i<n;i++)
{
for(j=0;j<i;j++)
{
if(i==0 || j==0)
{
a[i][j]=1;
}else {
a[i][j]=a[i-1][j]+a[i-1][j-1];
}
out.print(a[i][j]+" ");
}
%>
<br>
<%
}
%>
</body>
</html>
JSP以及js生成杨辉三角形
最新推荐文章于 2022-06-30 18:10:27 发布