JSP以及js生成杨辉三角形

<%@ 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>

    原文作者:杨辉三角问题
    原文地址: https://blog.csdn.net/ldutyk/article/details/52644942
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞