jsp完成三角信息处理
时间: 2024-03-22 22:19:08 浏览: 30
可以使用如下代码完成三角信息处理:
```jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>三角信息处理</title>
</head>
<body>
<h1>三角形信息处理</h1>
<%
// 获取输入的三个边长
int a = Integer.parseInt(request.getParameter("a"));
int b = Integer.parseInt(request.getParameter("b"));
int c = Integer.parseInt(request.getParameter("c"));
// 判断是否为合法的三角形
if (a + b > c && a + c > b && b + c > a) {
// 计算三角形的周长和面积
int perimeter = a + b + c;
double p = perimeter / 2.0;
double area = Math.sqrt(p * (p - a) * (p - b) * (p - c));
// 输出计算结果
out.println("<p>输入的三角形三边长分别为: " + a + ", " + b + ", " + c + "</p>");
out.println("<p>三角形的周长为: " + perimeter + "</p>");
out.println("<p>三角形的面积为: " + area + "</p>");
} else {
// 如果不是合法的三角形,输出错误信息
out.println("<p>输入的三边长不构成一个三角形,请重新输入!</p>");
}
%>
</body>
</html>
```
其中,`request.getParameter("a")`、`request.getParameter("b")`、`request.getParameter("c")`用于获取用户输入的三个边长。使用`if`语句判断是否为合法的三角形,如果是,计算三角形的周长和面积,并输出结果;如果不是,输出错误信息。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)