main.jsp ladder.jsp circle.jsp求圆的面积 梯形面积
时间: 2024-05-05 22:16:54 浏览: 229
jsp实验指导书.doc
5星 · 资源好评率100%
在main.jsp中引入circle.jsp和ladder.jsp,然后分别调用它们的计算圆面积和梯形面积的方法。
例如,在main.jsp中可以这样调用circle.jsp和ladder.jsp:
```
<%@ include file="circle.jsp" %>
<%@ include file="ladder.jsp" %>
<%
double radius = 5.0;
double circleArea = getCircleArea(radius);
out.println("圆的面积:" + circleArea);
double upperBase = 10.0;
double lowerBase = 8.0;
double height = 6.0;
double ladderArea = getLadderArea(upperBase, lowerBase, height);
out.println("梯形的面积:" + ladderArea);
%>
```
其中,getCircleArea和getLadderArea分别是在circle.jsp和ladder.jsp中定义的计算圆面积和梯形面积的方法,可以这样实现:
circle.jsp:
```
<%
double getCircleArea(double radius) {
double area = Math.PI * radius * radius;
return area;
}
%>
```
ladder.jsp:
```
<%
double getLadderArea(double upperBase, double lowerBase, double height) {
double area = (upperBase + lowerBase) * height / 2;
return area;
}
%>
```
阅读全文