用jsp写一个杨辉三角
时间: 2023-03-28 22:02:47 浏览: 111
可以使用以下代码实现:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>杨辉三角</title>
</head>
<body>
<%
int n = 10; // 控制杨辉三角的行数
int[][] arr = new int[n][n];
for (int i = ; i < n; i++) {
for (int j = ; j <= i; j++) {
if (j == || j == i) {
arr[i][j] = 1;
} else {
arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
}
}
}
for (int i = ; i < n; i++) {
for (int j = ; j <= i; j++) {
out.print(arr[i][j] + " ");
}
out.println("<br>");
}
%>
</body>
</html>
阅读全文